В настоящее время я пытаюсь создать 2D-платформер в Unity, все работает нормально, кроме одного. Когда я нажимаю «Влево» или «Вправо», анимация моего спрайта отражается в правильном направлении. В настоящее время я пытаюсь добавить вход контроллера, но я не могу настроить аналоговый сигнал влево или вправо. Он должен отражаться при нажатии на стик вправо и наоборот.
Надеюсь, кто-нибудь может мне помочь :)
#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;
}
}