所以我希望我的球员能够在无意间跌落的情况下上下梯子。爬上很容易,让他们向前走到墙上,他们会碰撞并保持静止但是当他们使用“后退”按钮下降时,他们将开始非常短暂地下降,但立即走下梯子。暂时禁用播放器脚本是一个混乱的过程,所以我想知道什么是一个好的选择。
我正在使用transform
在ladderScript
中提升和降低我的玩家,并将其移至playerScript
。
脚本(为简洁而修改)
public class LadderScript : MonoBehaviour {
private playerScript pScript; //<--These both contain the colliding players script...
private Collider collided; //<---- ...and collider when Update runs
private bool triggerStay; //used to prevent Update from running while there is no contact
void Start()
{
triggerStay = false;
}
...
void Update() //Runs once per collider that is touching the player every frame
{
if (triggerStay) {
if (collided.CompareTag ("Player")) { //A player is touching the ladder
/*
if (!pScript.getIsGrounded ()) { //Ineffective
pScript.enabled = false;
} else if (pScript.getIsGrounded ()) {
pScript.enabled = true;
}
*/
if (Input.GetAxis ("Vertical") < 0) { // Player should go down
collided.transform.Translate (0, -.1f, 0);
} else if (Input.GetAxis ("Vertical") > 0) //Player should go up
collided.transform.Translate (0, .1f, 0);
}
}
}
...
}