Create player controller(Player.cs)
This commit is contained in:
parent
92708715e6
commit
ddd1441675
4 changed files with 211 additions and 0 deletions
40
Assets/Scripts/Player.cs
Normal file
40
Assets/Scripts/Player.cs
Normal file
|
@ -0,0 +1,40 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Player : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField] private float moveSpeed = 7f;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
Vector2 inputVector = new Vector2(0,0);
|
||||
|
||||
if (Input.GetKey(KeyCode.W))
|
||||
{
|
||||
inputVector.y = +1;
|
||||
}
|
||||
if (Input.GetKey(KeyCode.S))
|
||||
{
|
||||
inputVector.y = -1;
|
||||
}
|
||||
if (Input.GetKey(KeyCode.A))
|
||||
{
|
||||
inputVector.x = -1;
|
||||
}
|
||||
if (Input.GetKey(KeyCode.D))
|
||||
{
|
||||
inputVector.x = +1;
|
||||
}
|
||||
|
||||
inputVector = inputVector.normalized;
|
||||
|
||||
Vector3 moveDir = new Vector3(inputVector.x, 0f, inputVector.y);
|
||||
transform.position += moveDir * moveSpeed * Time.deltaTime;
|
||||
|
||||
Debug.Log(inputVector);
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue