32 lines
842 B
C#
32 lines
842 B
C#
using UnityEngine;
|
|
|
|
public class HealthPack : MonoBehaviour
|
|
{
|
|
public int healAmount = 35;
|
|
public float rotateSpeed = 70f;
|
|
public float bobHeight = 0.15f;
|
|
public float bobSpeed = 2f;
|
|
|
|
private Vector3 _basePosition;
|
|
|
|
private void Start()
|
|
{
|
|
_basePosition = transform.position;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
transform.Rotate(Vector3.up, rotateSpeed * Time.deltaTime, Space.World);
|
|
transform.position = _basePosition + Vector3.up * (Mathf.Sin(Time.time * bobSpeed) * bobHeight);
|
|
}
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
PlayerHealth playerHealth = other.GetComponent<PlayerHealth>() ?? other.GetComponentInParent<PlayerHealth>();
|
|
if (playerHealth != null && playerHealth.Heal(healAmount))
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
}
|