Files
ClearTheZone/Assets/Scripts/PlayerController.cs
T
2026-08-20 10:43:24 +02:00

48 lines
999 B
C#

//Oliver
using UnityEngine;
using UnityEngine.UI;
public class PlayerController : MonoBehaviour
{
[SerializeField] int speed;
private Vector3 position = Vector3.zero;
private Text score;
private int points;
private Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
if (PauseMenu.GameIsPaused)
{
position = Vector3.zero;
return;
}
position = Vector3.zero;
if (Input.GetKey(KeyCode.W))
{
position += Vector3.forward * speed;
}
if (Input.GetKey(KeyCode.A))
{
position += Vector3.left * speed;
}
if (Input.GetKey(KeyCode.S))
{
position += Vector3.back * speed;
}
if (Input.GetKey(KeyCode.D))
{
position += Vector3.right * speed;
}
}
private void FixedUpdate()
{
rb.linearVelocity = position.normalized * speed;
}
}