下面的脚本附在我的游戏中的敌人身上。
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> ();
}下面的代码是让敌人在一定的距离上停下来,从扳机“攻击”中射击。(下面和上面都是相同的代码)。
// 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);
}
}这个脚本主要使用导航代理来让敌人向我的玩家靠近,并在敌人处于特定范围时开始射击动画。
任何帮助都是最好的。谢谢。
发布于 2017-03-04 03:29:10
您应该对检查使用布尔值,而不是触发器。你应该修改你的代码,当玩家不在攻击范围内时,将boolean攻击设置为false,当玩家在攻击范围内时,将boolean设置为true。此外,请确保您的动画片段循环已勾选。
https://stackoverflow.com/questions/42584443
复制相似问题