我想改变int速度值,但它不起作用。有人能帮我吗?如果你的信息太少,请问我。 这是我的代码:有人知道我在C#Unity3D中的if语句有什么问题吗?
if (Input.GetKeyDown (KeyCode.W)) {
sprint1 = true;
} else if (Input.GetKeyUp(KeyCode.W)){
sprint1 = false;
}
if (Input.GetKeyDown(KeyCode.LeftShift)){
sprint2 = true;
} else if (Input.GetKeyUp(KeyCode.LeftShift)){
sprint2 = false;
}
if (sprint2 == false && Input.GetKeyUp(KeyCode.W) && Input.GetKeyUp(KeyCode.A) && Input.GetKeyUp(KeyCode.S) && Input.GetKeyUp(KeyCode.D)){
speed = 0;
} if (sprint2==false && (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.D))){
speed = 4;
}if (sprint1 == true && sprint2 == true && Scoped==true) {
speed = 8;
}
此代码在'Update()'循环中吗? – Smartis
你调试了吗? –
如果'Input.GetKeyDown(KeyCode.W)'== false,'Input.GetKeyUp(KeyCode.W)'也可以为false吗?这个怎么样:'sprint1 = Input.GetKeyDown(KeyCode.W)' –