Files
JJBB/Assets/Project/Script/SceneMovie/MoveAction.cs

33 lines
857 B
C#
Raw Normal View History

2024-08-23 15:49:34 +08:00
using UnityEngine;
using UnityEngine.AI;
public class MoveAction : MonoBehaviour
{
public GameObject ControlModel;
public Vector3 Destant = Vector3.zero;
public float AgentSpeed = 5.0f;
public float AgentRadius = 0.3f;
public float AgentHeight = 2.0f;
public float AgentAngularSpeed = 30000;
private void OnEnable()
{
if (ControlModel == null) ControlModel = gameObject;
var Nav = ControlModel.EnsureComponent<NavMeshAgent>();
if (Nav != null)
{
Nav.speed = AgentSpeed;
Nav.radius = AgentRadius;
Nav.height = AgentHeight;
Nav.angularSpeed = AgentAngularSpeed;
if (Destant == Vector3.zero)
Nav.SetDestination(transform.position);
else
Nav.SetDestination(Destant);
}
}
}