first commit
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user