敵Animation追加

ごちゃごちゃ変えたから後でリファクタリング
This commit is contained in:
oogushiyuuga
2026-05-27 16:27:47 +09:00
parent 4141e2d189
commit b47e878d81
1468 changed files with 381106 additions and 622 deletions

View File

@@ -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()
{