Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.AI;
- namespace RPG.Movement
- {
- public class Mover : MonoBehaviour
- {
- [SerializeField] Transform target;
- public void Update()
- {
- UpdateAnimator();
- }
- public void MoveTo(Vector3 destination)
- {
- GetComponent<NavMeshAgent>().destination = destination;
- }
- private void UpdateAnimator()
- {
- Vector3 velocity = GetComponent<NavMeshAgent>().velocity;
- Vector3 localVelocity = transform.InverseTransformDirection(velocity);
- float speed = localVelocity.z;
- GetComponent<Animator>().SetFloat("forwardSpeed", speed);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement