Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.AI;
- public class Mover : MonoBehaviour, IAction
- {
- Transform target;
- NavMeshAgent nav;
- private void Start()
- {
- nav = GetComponent<NavMeshAgent>();
- }
- void Update()
- {
- UpdateAnimator();
- }
- public void StartMoveAction(Vector3 des)
- {
- GetComponent<ActionScedular>().StartAction(this);
- MoveTo(des);
- }
- public void MoveTo(Vector3 des)
- {
- GetComponent<NavMeshAgent>().destination = des;
- nav.isStopped = false;
- }
- public void Cancel()
- {
- nav.isStopped = true;
- }
- private void UpdateAnimator()
- {
- Vector3 velocity = GetComponent<NavMeshAgent>().velocity;
- Vector3 localVel = transform.InverseTransformDirection(velocity);
- float speed = localVel.z;
- GetComponent<Animator>().SetFloat("ForwardSpeed", speed);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement