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 Actor2D : MonoBehaviour
- {
- [SerializeField]
- GameObject followTarget;
- [SerializeField]
- Animator anim;
- [SerializeField]
- NavMeshAgent agent;
- [SerializeField]
- bool isFlying;
- private void Awake()
- {
- anim = GetComponent<Animator>();
- agent = followTarget.GetComponent<NavMeshAgent>();
- }
- private void Update()
- {
- if(!isFlying)
- {
- anim.SetBool("IsWalking",agent.velocity == Vector3.zero ? false : true);
- if(Mathf.Abs(agent.velocity.z) >= Mathf.Abs(agent.velocity.x))
- {
- anim.SetFloat("TargetZ", -agent.velocity.z);
- anim.SetFloat("TargetX", 0);
- }
- else
- {
- anim.SetFloat("TargetX", agent.velocity.x);
- anim.SetFloat("TargetZ", 0);
- }
- }
- }
- private void LateUpdate()
- {
- if(followTarget != null)
- {
- transform.localPosition = new Vector3(followTarget.transform.localPosition.x, followTarget.transform.localPosition.y, followTarget.transform.localPosition.z);
- }
- }
- }
Add Comment
Please, Sign In to add comment