追踪代码如下。这个问题真的把我难到了,希望有大佬能帮忙解答下,谢谢!
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;
}
}