using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
[SerializeField]
Transform mainCamera;
float scale = 0.1f;
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.W))
{
var direction = Quaternion.Euler(mainCamera.eulerAngles) * Vector3.forward;
transform.position += new Vector3(direction.x, 0, direction.z) * scale;
}
if (Input.GetKey(KeyCode.S))
{
var direction = Quaternion.Euler(mainCamera.transform.eulerAngles) * Vector3.back;
transform.localPosition += new Vector3(direction.x, 0, direction.z) * scale;
}
if (Input.GetKey(KeyCode.A))
{
var direction = Quaternion.Euler(mainCamera.transform.eulerAngles) * Vector3.left;
transform.localPosition += new Vector3(direction.x, 0, direction.z) * scale;
}
if (Input.GetKey(KeyCode.D))
{
var direction = Quaternion.Euler(mainCamera.transform.eulerAngles) * Vector3.right;
transform.localPosition += new Vector3(direction.x, 0, direction.z) * scale;
}
}
}
More than 3 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme