Super Knight : Enter the Dungeon
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.

34 lines
848 B

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Serialization;
public class DistanceHide : MonoBehaviour
{
Vector3 posStart = Vector2.zero;
public void OnInitialized(float distance)
{
this.distance = distance;
posStart = transform.position;
}
public float distance = 5f;
[System.Serializable]
public class GoalEvent : UnityEvent { }
[FormerlySerializedAs("onGoal")]
[SerializeField]
private GoalEvent OnGoal = new GoalEvent();
Vector3 tmp = Vector3.zero;
private void FixedUpdate()
{
tmp = transform.position;
tmp.y = posStart.y;
if (distance <= Mathf.Abs(Vector3.Distance(posStart, tmp)))
{
OnGoal.Invoke();
enabled = false;
}
}
}