2024-04-30 17:14:05 +01:00
|
|
|
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;
|
|
|
|
|
2024-04-30 17:31:29 +01:00
|
|
|
[Header("Audio")]
|
|
|
|
public AudioSource metalPipe;
|
|
|
|
|
2024-04-30 17:14:05 +01:00
|
|
|
|
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
rb = GetComponent<Rigidbody>();
|
|
|
|
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");
|
2024-04-30 17:31:29 +01:00
|
|
|
metalPipe.Play();
|
2024-04-30 17:14:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|