我正在创建一个 FPS 游戏,但我不知道如何循环播放附加了脚本的敌人的射击动画,直到我的玩家死亡

I'm creating an FPS game and I can't work out how to loop the shoot animation of the enemy I've attached the script to until my player dies

下面的脚本附在我游戏中的敌人身上。

using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

public class EnemyMovement : MonoBehaviour {

    private Animator attack;

    Transform player;

    UnityEngine.AI.NavMeshAgent nav;



    void Awake()
    {
        player = GameObject.FindGameObjectWithTag("Player").transform;

            nav = GetComponent<UnityEngine.AI.NavMeshAgent> ();

    }

下面的代码是让敌人在一定距离处停下来并用扳机开火 "Attack"。 (下面和上面都是一样的代码)

    // Update is called once per frame
    void Update () {


        nav.SetDestination(player.position);
        float distance = Vector3.Distance(this.transform.position, player.position);
        if (distance < 10f)
        {


            Animator an = GetComponent<Animator>();
                an.SetTrigger("Attack");

        }


        Debug.Log("distance" + distance);


    }

}

这个脚本主要是使用 Nav Agent 让敌人朝我的玩家走来,当敌人在一定范围内时开始射击动画。

任何帮助都会很棒。谢谢。

您应该使用布尔值而不是触发器来进行检查。您应该更改代码以在玩家不在范围内时将布尔值 Attacking 设置为 false,并在玩家在攻击范围内时将布尔值设置为 true。另外,请确保您的动画剪辑循环已勾选。