这个问题困扰了我几天了,希望大佬们能帮忙解答一下,谢谢!
代码如下:
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;
}
}