我想改變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)' –