Add three player and controller support
This commit is contained in:
@@ -5,6 +5,7 @@ using UnityEngine;
|
|||||||
public class PlayerController : MonoBehaviour
|
public class PlayerController : MonoBehaviour
|
||||||
{
|
{
|
||||||
public string playerNumber;
|
public string playerNumber;
|
||||||
|
public bool useController = false;
|
||||||
public float rotationSpeed = 100;
|
public float rotationSpeed = 100;
|
||||||
public float movementSpeed = 100;
|
public float movementSpeed = 100;
|
||||||
public Rigidbody rb;
|
public Rigidbody rb;
|
||||||
@@ -25,26 +26,36 @@ public class PlayerController : MonoBehaviour
|
|||||||
float rotationDirection = Input.GetAxis("Horizontal" + this.playerNumber);
|
float rotationDirection = Input.GetAxis("Horizontal" + this.playerNumber);
|
||||||
float movementDirection = Input.GetAxis("Vertical" + 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)
|
if (rotationDirection > 0)
|
||||||
{
|
{
|
||||||
transform.Rotate(Vector3.up, this.rotationSpeed * Time.deltaTime);
|
transform.Rotate(Vector3.up, this.rotationSpeed * Time.deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Rechts
|
||||||
if (rotationDirection < 0)
|
if (rotationDirection < 0)
|
||||||
{
|
{
|
||||||
transform.Rotate(Vector3.up, -this.rotationSpeed * Time.deltaTime);
|
transform.Rotate(Vector3.up, -this.rotationSpeed * Time.deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Forward
|
||||||
if (movementDirection > 0)
|
if (movementDirection > 0)
|
||||||
{
|
{
|
||||||
this.rb.AddRelativeForce(Vector3.forward * this.movementSpeed * Time.deltaTime, ForceMode.Impulse);
|
this.rb.AddRelativeForce(Vector3.forward * this.movementSpeed * Time.deltaTime, ForceMode.Impulse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Zurück
|
||||||
if (movementDirection < 0)
|
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)
|
if (Input.GetButtonDown("Boost" + this.playerNumber) && !this.lockBoost)
|
||||||
{
|
{
|
||||||
this.rb.AddRelativeForce(Vector3.forward * this.boostSpeed * Time.deltaTime, ForceMode.Impulse);
|
this.rb.AddRelativeForce(Vector3.forward * this.boostSpeed * Time.deltaTime, ForceMode.Impulse);
|
||||||
@@ -53,6 +64,7 @@ public class PlayerController : MonoBehaviour
|
|||||||
this.lockBoost = true;
|
this.lockBoost = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Irgendwas
|
||||||
if (Time.time > (this.lastBoostTime + this.boostDuration))
|
if (Time.time > (this.lastBoostTime + this.boostDuration))
|
||||||
{
|
{
|
||||||
this.lockBoost = false;
|
this.lockBoost = false;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ InputManager:
|
|||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_Axes:
|
m_Axes:
|
||||||
- serializedVersion: 3
|
- serializedVersion: 3
|
||||||
m_Name: Horizontal
|
m_Name: Horizontal1
|
||||||
descriptiveName:
|
descriptiveName:
|
||||||
descriptiveNegativeName:
|
descriptiveNegativeName:
|
||||||
negativeButton: left
|
negativeButton: left
|
||||||
@@ -38,7 +38,23 @@ InputManager:
|
|||||||
axis: 0
|
axis: 0
|
||||||
joyNum: 0
|
joyNum: 0
|
||||||
- serializedVersion: 3
|
- 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:
|
descriptiveName:
|
||||||
descriptiveNegativeName:
|
descriptiveNegativeName:
|
||||||
negativeButton: down
|
negativeButton: down
|
||||||
@@ -52,7 +68,7 @@ InputManager:
|
|||||||
invert: 0
|
invert: 0
|
||||||
type: 0
|
type: 0
|
||||||
axis: 0
|
axis: 0
|
||||||
joyNum: 0
|
joyNum: 16
|
||||||
- serializedVersion: 3
|
- serializedVersion: 3
|
||||||
m_Name: Vertical2
|
m_Name: Vertical2
|
||||||
descriptiveName:
|
descriptiveName:
|
||||||
@@ -69,6 +85,38 @@ InputManager:
|
|||||||
type: 0
|
type: 0
|
||||||
axis: 0
|
axis: 0
|
||||||
joyNum: 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
|
- serializedVersion: 3
|
||||||
m_Name: Fire1
|
m_Name: Fire1
|
||||||
descriptiveName:
|
descriptiveName:
|
||||||
@@ -326,7 +374,7 @@ InputManager:
|
|||||||
axis: 0
|
axis: 0
|
||||||
joyNum: 0
|
joyNum: 0
|
||||||
- serializedVersion: 3
|
- serializedVersion: 3
|
||||||
m_Name: Boost
|
m_Name: Boost1
|
||||||
descriptiveName: Is boost
|
descriptiveName: Is boost
|
||||||
descriptiveNegativeName:
|
descriptiveNegativeName:
|
||||||
negativeButton:
|
negativeButton:
|
||||||
@@ -357,3 +405,19 @@ InputManager:
|
|||||||
type: 0
|
type: 0
|
||||||
axis: 0
|
axis: 0
|
||||||
joyNum: 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
|
||||||
|
|||||||
Reference in New Issue
Block a user