You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
968 B
48 lines
968 B
using Ai; |
|
using UnityEngine; |
|
|
|
namespace Equip |
|
{ |
|
public class LootItem : MonoBehaviour { |
|
|
|
const float moveTime = 0.15f; |
|
Vector3 target; |
|
private float step; |
|
|
|
private bool _enabled; |
|
|
|
void Update () |
|
{ |
|
if (!_enabled) |
|
return; |
|
|
|
SetTarget(AiController.Instance.PlayerPosition); |
|
transform.position = Vector3.MoveTowards(transform.position, target, |
|
step / moveTime * Time.deltaTime); |
|
if (step < 1) |
|
{ |
|
SoundsManager.Instance.PlaySound("take_reward"); |
|
Destroy(gameObject); |
|
} |
|
} |
|
|
|
private void SetTarget (Vector3 position) { |
|
target = position; |
|
step = Vector3.Distance(transform.position, target); |
|
} |
|
private void OnEnable() |
|
{ |
|
AiController.Instance.StageCompletedEvent += OnStageComplete; |
|
} |
|
|
|
private void OnDisable() |
|
{ |
|
AiController.Instance.StageCompletedEvent -= OnStageComplete; |
|
} |
|
|
|
private void OnStageComplete() |
|
{ |
|
_enabled = true; |
|
} |
|
} |
|
}
|
|
|