我目前正在尝试在Unity中创建2d平台游戏,除了一件事情之外,一切工作都正常。当我向左或向右推,我的精灵动画镜像到正确的方向。我目前正在尝试添加控制器输入,但我似乎无法左右推动模拟器。推杆时它应该是镜像,反之亦然。Unity 2d平台游戏控制器支持
希望有人能帮助我:)
#pragma strict
var X : float;
function Start() {
//Gathering normal object scale
X = transform.localScale.x;
}
function Update() {
if(Input.GetKey("a")) {
// Gamer pushes left arrow key
// Set texture to normal position
transform.localScale.x = -X;
}
else if (Input.GetKey("d")) {
// Gamer pushes right arrow key
// Flip texture
transform.localScale.x = X;
}
if(Input.GetKey("left")) {
// Gamer pushes left arrow key
// Set texture to normal position
transform.localScale.x = -X;
}
else if (Input.GetKey("right")) {
// Gamer pushes right arrow key
// Flip texture
transform.localScale.x = X;
}
if(Input.GetAxis("Horizontal")) {
// Gamer pushes left arrow key
// Set texture to normal position
transform.localScale.x = -X;
}
else if (Input.GetAxis("Horizontal")) {
// Gamer pushes right arrow key
// Flip texture
transform.localScale.x = X;
}
}
你好,是的,它确实没什么意义,我现在在课堂上,所以我没有机会用我的控制器测试脚本。所以这个脚本意味着如果水平<0向左移动,并且如果水平> 0向右移动?统一自动理解我的左边模拟是否是输入? 除此之外,我还在unity的输入部分添加了我的有线控制器的D-pad。它确实有效,但我必须添加2个水平轴,一个用于D-pad的左侧箭头,另一个用于右侧。 –
@QuincyNorbert叶我不完全确定你如何设置输入,但有一个阅读下面的链接,看看是否有帮助... http://docs.unity3d.com/Documentation/ScriptReference/Input.GetAxis .html 因此,您已经创建了自己的定制d-pad? – Savlon
我试过你的方法,现在正在工作,非常感谢!我曾尝试过一次,但忘记在else if语句中添加> 0 –