敵Animation追加
ごちゃごちゃ変えたから後でリファクタリング
This commit is contained in:
@@ -28,17 +28,31 @@ public class EnemyAI : MonoBehaviour
|
||||
[SerializeField] private float wanderTimeout = 7f;
|
||||
|
||||
private NavMeshAgent agent;
|
||||
private Animator anim;
|
||||
private Transform playerTransform;
|
||||
private bool isWandering = false;
|
||||
|
||||
void Start()
|
||||
{
|
||||
agent = GetComponent<NavMeshAgent>();
|
||||
anim = GetComponent<Animator>();
|
||||
|
||||
// 負荷軽減のため、AIの思考ループをコルーチンで開始(毎フレーム Update で処理しない)
|
||||
StartCoroutine(AILoop());
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
// 1. NavMeshAgentの現在の速度(Vector3)の「大きさ(長さ)」を計算してフロート値にする
|
||||
// これにより、前後左右どの向きに動いていても「進んでいるスピード」が正の数値として取れます
|
||||
float currentSpeed = agent.velocity.magnitude;
|
||||
|
||||
Debug.Log($"[アニメデバッグ] 敵の計算速度: {currentSpeed:F2} | Animatorコンポーネント: {anim != null}");
|
||||
|
||||
// 2. Animatorの"Speed"パラメーターに数値を送る
|
||||
anim.SetFloat("Speed", currentSpeed);
|
||||
}
|
||||
|
||||
// AIの意思決定を行うメインループ(0.2秒ごとに実行して負荷を劇的に下げる)
|
||||
private IEnumerator AILoop()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user