Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
追跡対象が揃うまで待つ
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
You can’t perform that action at this time.