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.
59 lines
1.2 KiB
59 lines
1.2 KiB
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
[ExecuteInEditMode]
|
|
public class Waypoint : MonoBehaviour
|
|
{
|
|
|
|
|
|
[HideInInspector]
|
|
public Transform m_WaypointPosition;
|
|
|
|
public float m_WaitTime;
|
|
|
|
public string m_ModelName;
|
|
|
|
public float m_Index;
|
|
|
|
public bool m_Touched;
|
|
|
|
public delegate void WaypointReached(float index);
|
|
|
|
public static event WaypointReached OnWaypointReached;
|
|
|
|
public delegate void SwapModelOnReachingWaypoint(string modelName);
|
|
|
|
public static event SwapModelOnReachingWaypoint SwapModelOnWaypointReached;
|
|
|
|
private void OnEnable()
|
|
{
|
|
m_WaypointPosition = this.transform;
|
|
}
|
|
|
|
void OnTriggerEnter(Collider other)
|
|
{
|
|
if (other.transform.CompareTag("agent"))
|
|
{
|
|
CheckWaypoint();
|
|
}
|
|
}
|
|
|
|
private void CheckWaypoint()
|
|
{
|
|
if (OnWaypointReached != null && !m_Touched)
|
|
{
|
|
m_Touched = true;
|
|
OnWaypointReached(m_Index);
|
|
|
|
if (!string.IsNullOrEmpty(m_ModelName))
|
|
{
|
|
SwapModelOnWaypointReached(m_ModelName);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|