Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Created March 1, 2018 11:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsubaki/04c3e4c736118453ea7cbcac40c85e17 to your computer and use it in GitHub Desktop.
Save tsubaki/04c3e4c736118453ea7cbcac40c85e17 to your computer and use it in GitHub Desktop.
追跡対象が揃うまで待つ
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FollowAgent : MonoBehaviour {
[SerializeField] ExposeCharacterScene characterScene;
private UnityEngine.AI.NavMeshAgent agent;
private Animator animator;
private static int IDSpeed = Animator.StringToHash("Speed");
void Awake()
{
agent = GetComponent<UnityEngine.AI.NavMeshAgent>();
animator = GetComponent<Animator>();
}
IEnumerator Start()
{
enabled = false;
yield return new WaitWhile( ()=> characterScene.player == null);
enabled = true;
}
void Update ()
{
agent.SetDestination(characterScene.player.transform.position);
animator.SetFloat(IDSpeed, agent.velocity.magnitude, 0.13f, Time.deltaTime);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment