我正试着为一个篮板游戏做一个对话脚本。
这是我现在的密码。
#pragma strict
var keyNext : KeyCode;
var text = new Array();
var page = 0;
function OnCollisionEnter2D(col : Collision2D) {
Debug.Log ("COLLISION DETECTED");
if(col.gameObject.name == "NPC") {
text[0] = "hi";
text[1] = "bye";
} else {
Debug.Log("no text for "+col.gameObject.name);
}
Debug.Log(text.length);
if(Input.GetKey(keyNext) && text.length < page) {
page++;
}
Debug.Log(text[page]);
}
function OnCollisionExit2D(col : Collision2D) {
page = 0;
Debug.Log("walked away");
}
function update () {
}但是它只打印“hi”,当我按keyNext键(空格键)时,它不会去“拜拜”。
我希望有人能帮我!
发布于 2014-02-12 14:44:43
您正在OnCollisionEnter2D中签入OnCollisionEnter2D。尝试将其移动到Update,如:https://docs.unity3d.com/Documentation/ScriptReference/Input.GetKey.html
此外,您还可以考虑使用GetKeyUp而不是GetKey;https://docs.unity3d.com/Documentation/ScriptReference/Input.GetKeyUp.html。
https://stackoverflow.com/questions/21730888
复制相似问题