84 lines
2.5 KiB
C#
84 lines
2.5 KiB
C#
using Synty.AnimationBaseLocomotion.Samples;
|
|
using UnityEngine;
|
|
|
|
public class Pickup : MonoBehaviour
|
|
{
|
|
public enum PickupType { Health, Strength, StunBomb }
|
|
|
|
[Header("Pickup Settings")]
|
|
public PickupType type;
|
|
public float rotationSpeed = 90f; // Gives it that classic video game spin
|
|
|
|
[Header("Health Settings")]
|
|
public int healAmount = 50;
|
|
|
|
[Header("Strength Settings")]
|
|
public float strengthMultiplier = 2.0f; // Doubles damage and knockback
|
|
public float strengthDuration = 10f;
|
|
|
|
[Header("Stun Settings")]
|
|
public float stunRadius = 8f;
|
|
public float stunDuration = 5f;
|
|
public LayerMask enemyLayer;
|
|
|
|
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:
|
|
PlayerHealth health = player.GetComponent<PlayerHealth>();
|
|
if (health != null) health.Heal(healAmount);
|
|
break;
|
|
|
|
case PickupType.Strength:
|
|
SyntyPlayerCombat combat = player.GetComponentInChildren<SyntyPlayerCombat>();
|
|
if (combat != null) combat.ApplyStrengthBuff(strengthMultiplier, strengthDuration);
|
|
break;
|
|
|
|
case PickupType.StunBomb:
|
|
ExecuteStunBomb(transform.position);
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void ExecuteStunBomb(Vector3 center)
|
|
{
|
|
Collider[] hitEnemies = Physics.OverlapSphere(center, stunRadius, enemyLayer);
|
|
foreach (Collider enemyCollider in hitEnemies)
|
|
{
|
|
EnemyAI enemy = enemyCollider.GetComponentInParent<EnemyAI>();
|
|
if (enemy != null)
|
|
{
|
|
enemy.ApplyStun(stunDuration);
|
|
}
|
|
}
|
|
}
|
|
|
|
void OnDrawGizmosSelected()
|
|
{
|
|
if (type == PickupType.StunBomb)
|
|
{
|
|
Gizmos.color = Color.cyan;
|
|
Gizmos.DrawWireSphere(transform.position, stunRadius);
|
|
}
|
|
}
|
|
} |