Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Created August 7, 2016 15:18
Show Gist options
  • Save tsubaki/d29938b7133ac2bccd2526be5036b752 to your computer and use it in GitHub Desktop.
Save tsubaki/d29938b7133ac2bccd2526be5036b752 to your computer and use it in GitHub Desktop.
NavmeshとAnimatorの連携
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(Animator), typeof(NavMeshAgent))]
public class MoveNavigationWithAnimator : MonoBehaviour {
[SerializeField, HideInInspector] Animator animator;
[SerializeField, HideInInspector] NavMeshAgent agent;
[SerializeField] Transform target;
private static int paramIsStop = Animator.StringToHash ("IsStop");
void Reset()
{
animator = GetComponent<Animator> ();
agent = GetComponent<NavMeshAgent> ();
}
void Start ()
{
agent.SetDestination (target.position);
agent.updatePosition = false;
}
void Update()
{
animator.SetBool (paramIsStop, agent.remainingDistance < agent.stoppingDistance);
agent.nextPosition = transform.position;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment