Unity3d AI不工作?
你好,我正在尝试为我的角色创建一个ai,但它不起作用 我想让它一看到我的角色就拍,但它只是在场景中游荡而不是拍摄 甚至我的debug.log也不能工作Unity3d AI不工作?,unity3d,artificial-intelligence,Unity3d,Artificial Intelligence,你好,我正在尝试为我的角色创建一个ai,但它不起作用 我想让它一看到我的角色就拍,但它只是在场景中游荡而不是拍摄 甚至我的debug.log也不能工作 public Transform[] Targets; private int DestPoint = 0; private NavMeshAgent Agent; public Transform Player; public Rigidbody Bullet; public Transform Instantiator; void Star
public Transform[] Targets;
private int DestPoint = 0;
private NavMeshAgent Agent;
public Transform Player;
public Rigidbody Bullet;
public Transform Instantiator;
void Start()
{
Agent = GetComponent<NavMeshAgent> ();
Agent.autoBraking = false;
}
void Update()
{
if (Vector3.Distance(transform.position, Player.position) < 30f)
{
Debug.Log ("Shoot");
transform.LookAt (Player);
Shoot ();
}
else if (Vector3.Distance(transform.position, Player.position) > 30f)
{
GotoNextPoint ();
}
}
void GotoNextPoint()
{
Agent.destination = Targets [DestPoint].position;
DestPoint = (DestPoint + 1) % Targets.Length;
}
void Shoot()
{
Rigidbody Clone = Instantiate (Bullet, Instantiator.position, Instantiator.rotation) as Rigidbody;
Clone.AddForce (Vector3.forward);
}
public Transform[]目标;
私有点=0;
私人代理;
公共转换播放器;
公共刚体子弹;
公共转换实例化器;
void Start()
{
Agent=GetComponent();
Agent.autoBraking=false;
}
无效更新()
{
if(矢量3.距离(变换位置、玩家位置)<30f)
{
Debug.Log(“Shoot”);
变换。注视(运动员);
射击();
}
else if(矢量3.距离(变换位置、玩家位置)>30f)
{
GotoNextPoint();
}
}
void GotoNextPoint()
{
Agent.destination=目标[DestPoint]。位置;
DestPoint=(DestPoint+1)%Targets.Length;
}
空射()
{
刚体克隆=实例化(Bullet,Instantiator.position,Instantiator.rotation)为刚体;
Clone.AddForce(Vector3.forward);
}
距离绝对不会小于30。在您的else中:
else if (Vector3.Distance(transform.position, Player.position) > 30f)
{
GotoNextPoint ();
}
doDebug.Log(Vector3.Distance(transform.position,Player.position))代码>
因此,您可以看到您获得的价值:
else if (Vector3.Distance(transform.position, Player.position) > 30f)
{
Debug.Log(Vector3.Distance(transform.position, Player.position));
GotoNextPoint ();
}
如果debug.log不起作用,则Vector3.距离(transform.position,Player.position)
不得小于30。debug.log在之前的距离,如果,查看发生了什么