Files
BoostBaller/Assets/Scripts/PlayerController.cs

76 lines
2.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public string playerNumber;
public bool useController = false;
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 (this.useController) {
Debug.Log(Input.GetAxis("VerticalBack" + this.playerNumber));
movementDirection = Input.GetAxis("VerticalBack" + this.playerNumber) > 0 ? -1 : movementDirection;
}
//Links
if (rotationDirection > 0)
{
transform.Rotate(Vector3.up, this.rotationSpeed * Time.deltaTime);
}
//Rechts
if (rotationDirection < 0)
{
transform.Rotate(Vector3.up, -this.rotationSpeed * Time.deltaTime);
}
//Forward
if (movementDirection > 0)
{
this.rb.AddRelativeForce(Vector3.forward * this.movementSpeed * Time.deltaTime, ForceMode.Impulse);
}
//Zurück
if (movementDirection < 0)
{
this.rb.AddRelativeForce(Vector3.back * this.movementSpeed / 3 * Time.deltaTime, ForceMode.Impulse);
}
//Boost
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;
}
//Irgendwas
if (Time.time > (this.lastBoostTime + this.boostDuration))
{
this.lockBoost = false;
this.forceZone.SetActive(false);
}
}
}