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; public AudioClip boostSound; public Vector2 pitchModifier; private AudioSource audioSource; // Start is called before the first frame update void Start() { this.audioSource = this.forceZone.transform.GetComponent(); this.rb = GetComponent(); } // 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.audioSource.clip = this.boostSound; this.audioSource.pitch = Random.Range(this.pitchModifier.x, this.pitchModifier.y); this.rb.AddRelativeForce(Vector3.forward * this.boostSpeed * Time.deltaTime, ForceMode.Impulse); this.forceZone.SetActive(true); this.audioSource.Play(); this.lastBoostTime = Time.time; this.lockBoost = true; } //Irgendwas if (Time.time > (this.lastBoostTime + this.boostDuration)) { this.lockBoost = false; this.forceZone.SetActive(false); } } }