159 lines
4.6 KiB
C#
159 lines
4.6 KiB
C#
using Synty.AnimationBaseLocomotion.Samples;
|
|
using UnityEngine;
|
|
|
|
public class Pickup : MonoBehaviour
|
|
{
|
|
public enum PickupType { Health, Strength, StunBomb }
|
|
|
|
[Header("Pickup Settings")]
|
|
[SerializeField] private PickupType type;
|
|
[SerializeField] private float rotationSpeed = 90f; // Gives it that classic video game spin
|
|
|
|
[Header("Health Settings")]
|
|
[SerializeField] private int healAmount = 50;
|
|
[SerializeField] private GameObject healthVFX;
|
|
|
|
[Header("Strength Settings")]
|
|
[SerializeField] private float strengthMultiplier = 2.0f; // Doubles damage and knockback
|
|
[SerializeField] private float strengthDuration = 10f;
|
|
[SerializeField] private GameObject strengthVFX;
|
|
|
|
[Header("Stun Settings")]
|
|
[SerializeField] private float stunRadius = 8f;
|
|
[SerializeField] private float stunDuration = 5f;
|
|
[SerializeField] private LayerMask enemyLayer;
|
|
[SerializeField] private GameObject stunVFX;
|
|
|
|
// Cached components for performance
|
|
private PlayerHealth playerHealth;
|
|
private SyntyPlayerCombat syntyPlayerCombat;
|
|
private EnemyAI enemyAI;
|
|
|
|
void Update()
|
|
{
|
|
// Slowly rotate the pickup to make it visually obvious
|
|
transform.Rotate(Vector3.up, rotationSpeed * Time.deltaTime);
|
|
}
|
|
|
|
void OnTriggerEnter(Collider other)
|
|
{
|
|
// Make sure your Player Prefab has the "Player" Tag assigned at the very top of its Inspector!
|
|
if (other.CompareTag("Player"))
|
|
{
|
|
ApplyPickupEffect(other.gameObject);
|
|
|
|
// Optional: Play a sound or spawn a particle effect here before destroying
|
|
|
|
Destroy(gameObject); // Remove the pickup from the world
|
|
}
|
|
}
|
|
|
|
private void ApplyPickupEffect(GameObject player)
|
|
{
|
|
switch (type)
|
|
{
|
|
case PickupType.Health:
|
|
ApplyHealthPickup(player);
|
|
break;
|
|
|
|
case PickupType.Strength:
|
|
ApplyStrengthPickup(player);
|
|
break;
|
|
|
|
case PickupType.StunBomb:
|
|
ExecuteStunBomb(transform.position);
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void ApplyHealthPickup(GameObject player)
|
|
{
|
|
// Cache the component for performance
|
|
if (playerHealth == null)
|
|
{
|
|
playerHealth = player.GetComponent<PlayerHealth>();
|
|
if (playerHealth == null)
|
|
playerHealth = player.GetComponentInParent<PlayerHealth>();
|
|
}
|
|
|
|
if (playerHealth != null)
|
|
{
|
|
playerHealth.Heal(healAmount);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning("PlayerHealth component not found on player or its parent");
|
|
}
|
|
|
|
// Spawn VFX at pickup location
|
|
if (healthVFX != null)
|
|
{
|
|
Instantiate(healthVFX, transform.position, Quaternion.identity);
|
|
}
|
|
|
|
// Spawn VFX at player location
|
|
if (healthVFX != null && player != null)
|
|
{
|
|
Instantiate(healthVFX, player.transform.position + Vector3.up * 0.1f,
|
|
player.transform.rotation, player.transform);
|
|
}
|
|
}
|
|
|
|
private void ApplyStrengthPickup(GameObject player)
|
|
{
|
|
// Cache the component for performance
|
|
if (syntyPlayerCombat == null)
|
|
{
|
|
syntyPlayerCombat = player.GetComponent<SyntyPlayerCombat>();
|
|
}
|
|
|
|
if (syntyPlayerCombat != null)
|
|
{
|
|
syntyPlayerCombat.ApplyStrengthBuff(strengthMultiplier, strengthDuration);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning("SyntyPlayerCombat component not found on player");
|
|
}
|
|
|
|
// Spawn VFX at pickup location
|
|
if (strengthVFX != null)
|
|
{
|
|
Instantiate(strengthVFX, transform.position, transform.rotation);
|
|
}
|
|
}
|
|
|
|
private void ExecuteStunBomb(Vector3 center)
|
|
{
|
|
Collider[] hitEnemies = Physics.OverlapSphere(center, stunRadius, enemyLayer);
|
|
foreach (Collider enemyCollider in hitEnemies)
|
|
{
|
|
// Cache the component for performance
|
|
if (enemyAI == null)
|
|
{
|
|
enemyAI = enemyCollider.GetComponentInParent<EnemyAI>();
|
|
}
|
|
|
|
if (enemyAI != null)
|
|
{
|
|
enemyAI.ApplyStun(stunDuration);
|
|
}
|
|
}
|
|
|
|
// Spawn VFX at pickup location
|
|
if (stunVFX != null)
|
|
{
|
|
Instantiate(stunVFX, transform.position, transform.rotation);
|
|
}
|
|
}
|
|
|
|
void OnDrawGizmosSelected()
|
|
{
|
|
if (type == PickupType.StunBomb)
|
|
{
|
|
Gizmos.color = Color.cyan;
|
|
Gizmos.DrawWireSphere(transform.position, stunRadius);
|
|
}
|
|
}
|
|
}
|