【Unity2D】敌人跟踪时会和玩家一起跳跃,请问如何禁止敌人的跳跃让他只在x轴上跟踪?
作者:互联网
这个问题困扰了我几天了,希望大佬们能帮忙解答一下,谢谢!
代码如下:
void Update()
{
//判断玩家与BOSS之间的距离并存储
float distance = Vector2.Distance(PlayerController.player_Transform.position,transform.position);
//如果BOSS与玩家之间的距离大于5时,Trace_keep = true
if (distance>5)
{
Trace_keep = true;
if (Trace_keep == true)
{
//追踪,boss存储了刚体组件
transform.position = Vector2.MoveTowards(boss.position, PlayerController.player_Transform.position, 0.2f);
}
}
//如果BOSS与玩家之间的距离小于或等于3时,停止追踪
else if (distance<=3)
{
Trace_keep = false;
}
}
标签:Trace,Unity2D,BOSS,keep,跟踪,跳跃,position,玩家,true 来源: https://blog.csdn.net/qq_43532833/article/details/113850062