b58221dc98
player waypoint indicator walk and idle animations stop when menu opens
48 lines
1.2 KiB
C#
48 lines
1.2 KiB
C#
using UnityEngine;
|
|
using UnityEngine.AI;
|
|
|
|
public class CharacterMovement : MonoBehaviour
|
|
{
|
|
public NavMeshAgent player;
|
|
public Animator playerAnimator;
|
|
public Camera playerCamera;
|
|
public ParticleSystem targetDest;
|
|
public bool allowMovement=true;
|
|
|
|
void Start()
|
|
{
|
|
allowMovement = true;
|
|
}
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (allowMovement)
|
|
{
|
|
if (Input.GetMouseButton(0))
|
|
{
|
|
Ray myRay = playerCamera.ScreenPointToRay(Input.mousePosition);
|
|
|
|
if (Physics.Raycast(myRay, out RaycastHit hit))
|
|
{
|
|
targetDest.transform.position = hit.point;
|
|
targetDest.Play();
|
|
player.SetDestination(hit.point);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
player.SetDestination(player.transform.position);
|
|
player.velocity=Vector3.zero;
|
|
}
|
|
if(player.velocity!=Vector3.zero)
|
|
{
|
|
playerAnimator.SetBool("IsWalking",true);
|
|
}
|
|
else if (player.velocity == Vector3.zero)
|
|
{
|
|
playerAnimator.SetBool("IsWalking", false);
|
|
}
|
|
}
|
|
}
|