简体   繁体   English

Unity中简单的键盘输入

[英]simple keyboard input in Unity

I tried this in Unity with C# but I keep getting compiling error messages 我在Unity中使用C#尝试了此操作,但不断收到错误消息

void update ()
{ 
    if(Input.GetKeyDown(KeyCode.LeftArrow))
    { 
        transform.Translate(-1,0,0);
    }
}

where's the error? 错误在哪里? any alternative to perform simple movements? 还有其他方法可以执行简单的动作吗?

Your "update" method needs to be capitalized for Unity to recognize it. 您的“更新”方法需要大写,以便Unity识别。 Your script will not hook in unless Unity can see that the method name matches one of the ones it's looking for. 除非Unity可以看到方法名称与它要查找的名称之一匹配,否则您的脚本将不会挂接。 As for an alternative for simple movements, watch some tutorials on how CharacterControllers work. 至于简单动作的替代方法,请观看有关CharacterControllers如何工作的一些教程。 They have two functions that are pretty easy to use, which are Move, and SimpleMove. 它们具有两个非常易于使用的功能,即Move和SimpleMove。

"update" cahnge to Update “更新”更新

and

void update () { 

if(Input.GetKeyDown(KeyCode.LeftArrow)){ 

//(BAd usage)transform.Translate(-1,0,0);
transform.Translate(new Vector3(-1,0,0));
}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM