를 사용하는 것처럼 보인다 무효화 할 수있는 기능을 변경 :
편집이)
은 당신을 도와 바랍니다. Inspector에서 키 코드를 지정하지 않아도됩니다. 스크립트에서 직접 액세스 할 수 있습니다. 스크립트를 단순화해야합니다. 대신이의
:
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));
}
}
}
이 시도 :
using UnityEngine;
using System.Collections;
public class MoveRacket : MonoBehaviour
{
public float speed = 30f;
//the speed at which you move at. Value can be changed if you want
void Update()
{
// up key pressed?
if (Input.GetKeyDown(KeyCode.W)
{
transform.Translate(Vector2.up * speed * time.deltaTime, Space.world);
}
// down key pressed?
if (Input.GetKeyDown(KeyCode.S))
{
transform.Translate(Vector2.down * speed * time.deltaTime, Space.World);
}
}
}
당신이 운동을 위해 WASD 키를 사용하려면 가정. 원하는 경우 OR 수정 자 (||)를 사용하여 추가 할 수 있습니다. 또한 두 번째 플레이어의 경우 키 코드를 변경해야합니다. 그렇지 않으면 두 패들이 동시에 이동합니다.
코드 설명 : 속도 변수는 이동할 속도입니다. 필요에 따라 변경하십시오.
in transfor.Translate(), 일정한 속도로 시간 경과에 따라 세계 좌표 (로컬이 아님)로 이동하려고합니다. 그래서 Vector2.up * speed * time.deltaTime을 사용합니다. Vector2.up은이 프레임에서 이동하는 거리를 얻기 위해, 다음 Time.deltaTime에 의해 이동 거리를 얻기 위해 속도에 의해 곱
new Vector2 (0f, 1f);
과 동일합니다. Update는 매 프레임마다 호출되므로 매 프레임마다 거리를 이동합니다. 아래로 이동에서
는 Vector2.down는
new Vector2(0f, -1f);
희망이 도움과 동일합니다!
ifs에서 디버깅을 시도 했습니까? 무언가를 인쇄하여 조건에 들어가는 지 확인하십시오. –