【发布时间】:2022-01-19 02:44:01
【问题描述】:
所以我想知道是否有一种方法可以让玩家只需单击一下就可以无限移动,并在与另一个对撞机发生碰撞时停止。
【问题讨论】:
所以我想知道是否有一种方法可以让玩家只需单击一下就可以无限移动,并在与另一个对撞机发生碰撞时停止。
【问题讨论】:
您可以创建一个全局属性:
bool movePlayer = false;
在 FixedUpdate 方法中,您可以检测鼠标点击并将 movePlayer 更改为 true,如果值为 true,则移动播放器:
void FixedUpdate() {
if (Input.GetMouseButtonDown(0))
movePlayer = true;
if (movePlayer) {
//move the player here, maybe with Translate method
}
}
使用 OnTriggerEnter 方法可以检测碰撞并将 movePlayer 更改为 false:
void OnTriggerEnter(Collider other) {
//you can check for some particular object or avoid this if
if (other.gameObject.name == "SomeObject")
movePlayer = false;
}
【讨论】: