OldBlueWater/BlueWater/Assets/02.Scripts/TestMove.cs

40 lines
845 B
C#
Raw Normal View History

using System;
using UnityEngine;
using UnityEngine.AI;
public class TestMove : MonoBehaviour
{
public NavMeshAgent agent;
public Animator animator;
private void Awake()
{
agent = GetComponent<NavMeshAgent>();
animator = transform.GetChild(0).GetComponent<Animator>();
}
private void Update()
{
if (agent.velocity != Vector3.zero)
{
animator.SetFloat("RunState", 0.5f);
}
else
{
animator.SetFloat("RunState", 0f);
}
var localScale = animator.transform.localScale;
if (agent.velocity.x >= 0)
{
localScale.x = -Mathf.Abs(localScale.x);
}
else
{
localScale.x = Mathf.Abs(localScale.x);
}
animator.transform.localScale = localScale;
}
}