我目前正在嘗試在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 –