반응형
- 방향키로 이동
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerMove : MonoBehaviour
{
public float moveSpeed = 5.0f;
private void FixedUpdate() //키보드로 이동
{
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
transform.position += new Vector3(h, 0, v) * moveSpeed * Time.deltaTime;
}
}
- 키보드로 이동
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerMove : MonoBehaviour
{
public float moveSpeed = 1.0f;
private void FixedUpdate()
{
if (Input.GetKey(KeyCode.W))
transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
if (Input.GetKey(KeyCode.A))
transform.Translate(Vector3.left * moveSpeed * Time.deltaTime);
if (Input.GetKey(KeyCode.S))
transform.Translate(Vector3.down * moveSpeed * Time.deltaTime);
if (Input.GetKey(KeyCode.D))
transform.Translate(Vector3.right * moveSpeed * Time.deltaTime);
}
}
반응형
'개발 > C#' 카테고리의 다른 글
유니티 C# 코루틴 동작, 시간 딜레이 Coroutine, Invoke 간단 사용법 (0) | 2022.06.21 |
---|---|
유니티 C# 씬 로드 동기, 비동기 간단 사용법 Load Scene Async (0) | 2022.06.21 |
유니티 C# 랜덤 난수 생성 Random.Range 간단 사용법 (0) | 2022.06.21 |
유니티 C# 특수문자 제한 간단 사용법 input text (0) | 2022.06.21 |
유니티 C# 키보드 입력 Keyboard input 간단 사용법 (0) | 2022.06.20 |
유니티 C# 윈도우 창 애니메이션 Window Animation 간단 사용법 (0) | 2022.06.20 |
유니티 C# CSV 파일 저장, 불러오기 Read, Write 간단 사용법 (1) | 2022.06.20 |
유니티 C# 인앱결제 시스템 IAP Manager 간단 사용법 (0) | 2022.06.19 |
댓글