using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using UnityEngine; public class PlayerController : MonoBehaviour { [Header("Keybinds")] public KeyCode forwardKey = KeyCode.W; public KeyCode backwardKey = KeyCode.S; public KeyCode leftKey = KeyCode.A; public KeyCode rightKey = KeyCode.D; [Header("Speed")] public float speed = 5; [Header("Player Object")] public Vector3 moveDirection; public Rigidbody rb; [Header("Audio")] public AudioSource metalPipe; void Start() { rb = GetComponent(); rb.freezeRotation = true; } void Update() { moveDirection = PlayerInput(); rb.velocity = moveDirection.normalized * speed; } Vector3 PlayerInput() { float forward = Convert.ToSingle(Input.GetKey(forwardKey)); float backward = Convert.ToSingle(Input.GetKey(backwardKey)); float right = Convert.ToSingle(Input.GetKey(rightKey)); float left = Convert.ToSingle(Input.GetKey(leftKey)); return new Vector3(right - left, 0, forward - backward); } void OnCollisionEnter(Collision collision) { if (collision.gameObject.name == "Enemy") { Debug.Log("OWIE"); metalPipe.Play(); } } }