반응형
- 방향키로 이동
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);
}
}
반응형