Skip to content
Snippets Groups Projects
Commit ae5097c0 authored by clg544's avatar clg544
Browse files

Added Interface for Xbox controllers

parent 265788b7
No related branches found
No related tags found
3 merge requests!8Develop,!6Develop,!5Added Interface for Xbox controllers
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GamepadInput : MonoBehaviour {
[SerializeField]
float Deadzone;
float maxComparable;
[SerializeField]
PlayerBehavior myPlayer;
// Use this for initialization
void Start () {
maxComparable = 1 - Deadzone;
}
// Update is called once per frame
void Update () {
float leftX = Input.GetAxis("Left Horizontal");
float leftY = Input.GetAxis("Left Vertical");
/* Ratio of joystick amount over the deadzone */
myPlayer.MoveHorizontal(leftX);
myPlayer.MoveVertical(leftY);
if (Input.GetButton("Xbox B"))
myPlayer.Brake();
}
}
fileFormatVersion: 2
guid: 9ae2cb071c24c534ca4556fd157e062a
timeCreated: 1506465138
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -17,10 +17,10 @@ public class InputManagerScript : MonoBehaviour {
playerOneBehavior = playerOne.GetComponent<PlayerBehavior>();
playerTwoBehavior = playerTwo.GetComponent<PlayerBehavior>();
}
// Update is called once per frame
void Update () {
private void KeyboardInput()
{
/**
* Player One Movement Controls
*/
......@@ -71,4 +71,21 @@ public class InputManagerScript : MonoBehaviour {
playerTwoBehavior.Brake();
}
}
public void JoypadOneInput()
{
playerOneBehavior.MoveHorizontal(Input.GetAxis("Left Horizontal"));
playerOneBehavior.MoveVertical(Input.GetAxis("Left Vertical"));
if (Input.GetButton("Xbox B"))
playerOneBehavior.Brake();
}
// Update is called once per frame
void Update () {
KeyboardInput();
JoypadOneInput();
}
}
......@@ -40,22 +40,31 @@ public class PlayerBehavior : MonoBehaviour {
{
frameMovement.x -= acceleration;
}
public void MoveRight()
{
frameMovement.x += acceleration;
}
public void MoveUp()
{
frameMovement.y += acceleration;
}
public void MoveDown()
{
frameMovement.y -= acceleration;
}
public void MoveHorizontal(float f)
{
if(Mathf.Abs(f) <= 1)
frameMovement.x += f;
}
public void MoveVertical(float f)
{
if (Mathf.Abs(f) <= 1)
frameMovement.y += f;
}
/**
* Scale the player's velocity down, if brakeFraction is < zero
*/
......
......@@ -6,7 +6,7 @@ InputManager:
serializedVersion: 2
m_Axes:
- serializedVersion: 3
m_Name: Horizontal
m_Name: Left Horizontal
descriptiveName:
descriptiveNegativeName:
negativeButton: left
......@@ -14,15 +14,15 @@ InputManager:
altNegativeButton: a
altPositiveButton: d
gravity: 3
dead: 0.001
dead: 0.3
sensitivity: 3
snap: 1
invert: 0
type: 0
type: 2
axis: 0
joyNum: 0
joyNum: 1
- serializedVersion: 3
m_Name: Vertical
m_Name: Left Vertical
descriptiveName:
descriptiveNegativeName:
negativeButton: down
......@@ -30,266 +30,26 @@ InputManager:
altNegativeButton: s
altPositiveButton: w
gravity: 3
dead: 0.001
dead: 0.3
sensitivity: 3
snap: 1
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Fire1
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: left ctrl
altNegativeButton:
altPositiveButton: mouse 0
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Fire2
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: left alt
altNegativeButton:
altPositiveButton: mouse 1
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Fire3
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: left shift
altNegativeButton:
altPositiveButton: mouse 2
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Jump
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: space
altNegativeButton:
altPositiveButton:
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Mouse X
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton:
altNegativeButton:
altPositiveButton:
gravity: 0
dead: 0
sensitivity: 0.1
snap: 0
invert: 0
type: 1
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Mouse Y
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton:
altNegativeButton:
altPositiveButton:
gravity: 0
dead: 0
sensitivity: 0.1
snap: 0
invert: 0
type: 1
axis: 1
joyNum: 0
- serializedVersion: 3
m_Name: Mouse ScrollWheel
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton:
altNegativeButton:
altPositiveButton:
gravity: 0
dead: 0
sensitivity: 0.1
snap: 0
invert: 0
type: 1
axis: 2
joyNum: 0
- serializedVersion: 3
m_Name: Horizontal
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton:
altNegativeButton:
altPositiveButton:
gravity: 0
dead: 0.19
sensitivity: 1
snap: 0
invert: 0
type: 2
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Vertical
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton:
altNegativeButton:
altPositiveButton:
gravity: 0
dead: 0.19
sensitivity: 1
snap: 0
invert: 1
type: 2
axis: 1
joyNum: 0
- serializedVersion: 3
m_Name: Fire1
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: joystick button 0
altNegativeButton:
altPositiveButton:
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Fire2
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: joystick button 1
altNegativeButton:
altPositiveButton:
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Fire3
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: joystick button 2
altNegativeButton:
altPositiveButton:
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
joyNum: 1
- serializedVersion: 3
m_Name: Jump
m_Name: Xbox B
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: joystick button 3
positiveButton: joystick 1 button 1
altNegativeButton:
altPositiveButton:
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Submit
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: return
altNegativeButton:
altPositiveButton: joystick button 0
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Submit
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: enter
altNegativeButton:
altPositiveButton: space
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Cancel
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: escape
altNegativeButton:
altPositiveButton: joystick button 1
gravity: 1000
dead: 0.001
dead: 0
sensitivity: 1000
snap: 0
snap: 1
invert: 0
type: 0
axis: 0
joyNum: 0
joyNum: 1
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment