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;

View File

@@ -6,7 +6,7 @@ InputManager:
serializedVersion: 2
m_Axes:
- serializedVersion: 3
m_Name: Horizontal
m_Name: Horizontal1
descriptiveName:
descriptiveNegativeName:
negativeButton: left
@@ -38,7 +38,23 @@ InputManager:
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Vertical
m_Name: Horizontal3
descriptiveName:
descriptiveNegativeName:
negativeButton: left
positiveButton: right
altNegativeButton:
altPositiveButton:
gravity: 100000
dead: 0.3
sensitivity: 1
snap: 1
invert: 0
type: 2
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Vertical1
descriptiveName:
descriptiveNegativeName:
negativeButton: down
@@ -52,7 +68,7 @@ InputManager:
invert: 0
type: 0
axis: 0
joyNum: 0
joyNum: 16
- serializedVersion: 3
m_Name: Vertical2
descriptiveName:
@@ -69,6 +85,38 @@ InputManager:
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Vertical3
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton:
altNegativeButton:
altPositiveButton:
gravity: 10000
dead: 0.02
sensitivity: 3
snap: 1
invert: 0
type: 2
axis: 2
joyNum: 0
- serializedVersion: 3
m_Name: VerticalBack3
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: joystick button 5
altNegativeButton:
altPositiveButton:
gravity: 10000
dead: 0.2
sensitivity: 1
snap: 1
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Fire1
descriptiveName:
@@ -326,7 +374,7 @@ InputManager:
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Boost
m_Name: Boost1
descriptiveName: Is boost
descriptiveNegativeName:
negativeButton:
@@ -357,3 +405,19 @@ InputManager:
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Boost3
descriptiveName: Is boost
descriptiveNegativeName:
negativeButton:
positiveButton:
altNegativeButton:
altPositiveButton: joystick button 4
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 8
joyNum: 0