기본 이동, 네트워크, 카메라 설정 + 기본 애셋 추가
This commit is contained in:
34
Assets/Scripts/PlayerController.cs
Normal file
34
Assets/Scripts/PlayerController.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(Rigidbody))]
|
||||
public class PlayerController : MonoBehaviour
|
||||
{
|
||||
[Header("Movement Settings")]
|
||||
[SerializeField] private float moveSpeed = 5f;
|
||||
|
||||
private Rigidbody rb;
|
||||
private Vector3 moveDirection;
|
||||
|
||||
void Start()
|
||||
{
|
||||
rb = GetComponent<Rigidbody>();
|
||||
rb.constraints = RigidbodyConstraints.FreezeRotation;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
float horizontal = Input.GetAxisRaw("Horizontal");
|
||||
float vertical = Input.GetAxisRaw("Vertical");
|
||||
|
||||
moveDirection = new Vector3(horizontal, 0f, vertical).normalized;
|
||||
}
|
||||
|
||||
void FixedUpdate()
|
||||
{
|
||||
rb.linearVelocity = new Vector3(
|
||||
moveDirection.x * moveSpeed,
|
||||
rb.linearVelocity.y,
|
||||
moveDirection.z * moveSpeed
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user