Advertisement
Dijanka

Mover

Jan 21st, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.AI;
  3.  
  4. namespace RPG.Movement
  5. {
  6. public class Mover : MonoBehaviour
  7. {
  8. [SerializeField] Transform target;
  9.  
  10. public void Update()
  11. {
  12. UpdateAnimator();
  13. }
  14.  
  15.  
  16.  
  17. public void MoveTo(Vector3 destination)
  18. {
  19. GetComponent<NavMeshAgent>().destination = destination;
  20. }
  21.  
  22. private void UpdateAnimator()
  23. {
  24. Vector3 velocity = GetComponent<NavMeshAgent>().velocity;
  25. Vector3 localVelocity = transform.InverseTransformDirection(velocity);
  26. float speed = localVelocity.z;
  27. GetComponent<Animator>().SetFloat("forwardSpeed", speed);
  28.  
  29. }
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement