Add three player and controller support

This commit is contained in:
2019-09-26 00:46:45 +02:00
parent 56f6a77b62
commit 3499961a98
2 changed files with 81 additions and 5 deletions

View File

@@ -5,6 +5,7 @@ using UnityEngine;
public class PlayerController : MonoBehaviour
{
public string playerNumber;
public bool useController = false;
public float rotationSpeed = 100;
public float movementSpeed = 100;
public Rigidbody rb;
@@ -25,26 +26,36 @@ public class PlayerController : MonoBehaviour
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 * Time.deltaTime, ForceMode.Impulse);
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);
@@ -53,6 +64,7 @@ public class PlayerController : MonoBehaviour
this.lockBoost = true;
}
//Irgendwas
if (Time.time > (this.lastBoostTime + this.boostDuration))
{
this.lockBoost = false;