64 lines
1.9 KiB
C#
64 lines
1.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class PlayerController : MonoBehaviour
|
|
{
|
|
public string playerNumber;
|
|
public float rotationSpeed = 100;
|
|
public float movementSpeed = 100;
|
|
public Rigidbody rb;
|
|
public GameObject forceZone;
|
|
public float boostSpeed = 0;
|
|
public float boostDuration = 0;
|
|
public float lastBoostTime = 0;
|
|
public bool lockBoost = false;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
this.rb = GetComponent<Rigidbody>();
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
float rotationDirection = Input.GetAxis("Horizontal" + this.playerNumber);
|
|
float movementDirection = Input.GetAxis("Vertical" + this.playerNumber);
|
|
|
|
if (rotationDirection > 0)
|
|
{
|
|
transform.Rotate(Vector3.up, this.rotationSpeed * Time.deltaTime);
|
|
}
|
|
|
|
if (rotationDirection < 0)
|
|
{
|
|
transform.Rotate(Vector3.up, -this.rotationSpeed * Time.deltaTime);
|
|
}
|
|
|
|
if (movementDirection > 0)
|
|
{
|
|
this.rb.AddRelativeForce(Vector3.forward * this.movementSpeed * Time.deltaTime, ForceMode.Impulse);
|
|
}
|
|
|
|
if (movementDirection < 0)
|
|
{
|
|
this.rb.AddRelativeForce(Vector3.back * this.movementSpeed * Time.deltaTime, ForceMode.Impulse);
|
|
}
|
|
|
|
if (Input.GetButtonDown("Boost" + this.playerNumber) && !this.lockBoost)
|
|
{
|
|
this.rb.AddRelativeForce(Vector3.forward * this.boostSpeed * Time.deltaTime, ForceMode.Impulse);
|
|
this.forceZone.SetActive(true);
|
|
this.lastBoostTime = Time.time;
|
|
this.lockBoost = true;
|
|
}
|
|
|
|
if (Time.time > (this.lastBoostTime + this.boostDuration))
|
|
{
|
|
this.lockBoost = false;
|
|
this.forceZone.SetActive(false);
|
|
}
|
|
|
|
}
|
|
}
|