2014-10-11 2 views
0

시작하기 전에 나는 단결 멍청하다고 얘기해야합니다. Unity keypress not registered

그래서 나는 탁구 자습서를 다음되었지만, 나는 문제가있다. 화살표를 누르면 라켓이 움직이지 않습니다. 당신이 해결하는 방법을 알고 있다면이 나를

내 코드를 알려 주시기 바랍니다 :

using UnityEngine; 
using System.Collections; 

public class MoveRacket : MonoBehaviour { 
// up and down keys (to be set in the Inspector) 
public KeyCode up; 
public KeyCode down; 

void FixedUpdate() { 
    // up key pressed? 
    if (Input.GetKey(up)) { 
     transform.Translate(new Vector2(0.0f, 0.1f)); 
    } 

    // down key pressed? 
    if (Input.GetKey(down)) { 
     transform.Translate(new Vector2(0.0f, -0.1f)); 
    } 
} 
} 

및 제어 따기 옵션 : What shows up when I add the script in the inspector

+0

실제로 콤보 상자에서 위아래로 할당합니까? –

+0

중복 질문 #http : //stackoverflow.com/questions/26318390/key-input-wont-work-in-unity/26318448에 noredirect = 1 #의 comment41302388_26318448 두 번 질문을하지 마십시오 ... 당신은 할 수 없습니다 다음 답변을 찾을 그냥 몇 시간 동안 기다린 그 후 다시 시도하거나 채팅을 물어 http://chat.stackoverflow.com/rooms/37624/unity3d-developers –

답변

0

당신은 당신이 화살표를 누르면 움직이지 않는다고 말했다. 키 코드 지정에 따라 W 또는 S을 눌러야합니다.

+0

나는 그것을 변화 시도하지만 여전히하지 않았다 작동 :( – user1627724

+0

더, 나는 당신이? 내가 이런 일이 발생하는 또 다른 이유 생각할 수 없다 당신이 장면의 오브젝트에 스크립트를 부착하고 확실 WS로 제어 및 화살표 – user1627724

+0

한 2 개의 라켓 하나있다. 그것은이다 – devil0150

0
just change the name of your method FxedUpdate() to Update() 

using UnityEngine; 
using System.Collections; 

public class MoveRacket : MonoBehaviour { 
// up and down keys (to be set in the Inspector) 
public KeyCode up; 
public KeyCode down; 

void Update() { 
// up key pressed? 
if (Input.GetKey(up)) { 
    transform.Translate(new Vector2(0.0f, 0.1f)); 
} 

// down key pressed? 
if (Input.GetKey(down)) { 
    transform.Translate(new Vector2(0.0f, -0.1f)); 
} 
} 
} 
+0

왜 OP가 그렇게해야합니까? 'FixedUpdate()'및 'Update()'입력의 경우 많이 변경하지 마십시오. – FunctionR

0

당신이 유니티 에디터에서 실수를하지 않도록 실제 솔루션입니다.

void FixUodate() 
{ 
    if(Input.GetKey(KeyCode.UpArrow)) 
     transform.Translate(new Vector2(0.0f, 0.1f)); 


    else if (Input.GetKey(KeyCode.DownArrow)) 
     transform.Translate(new Vector2(0.0f, -0.1f)); 
}