Hi everyone.
I want to make it so I have support for both: my keyboard, my xbox controller, my dualshock 4 and any other controller I might want to ad in the future.
I tried to just add the button mappings to Unity’s input list but I found out that it read some dualshock inputs as inputs from the xbox controller.
That won’t do becouse it will mess up my controls when I try to use ether one.
I want it to reconise every controller automatically when I press a button and don’t want to have to switch it in the menu.
I know there are plugins for this, but I want to do my project without them.
So does anyone know how I can map this in Unity?
PS: I already have some code that I wanted to use as an input combiner but I probably have to rewrite everything once I have the solution, also it’s not finished because I stopped writing when I realised that dualshock 4 used some of the xbox controllers inputs.
Here is my code:
using UnityEngine;
using System.Collections;
public class ControlMapper : MonoBehaviour {
//*Camera inputs*
private float camXinput = 0.0f;
private float camYinput = 0.0f;
//Keyboard and mouse
private float mouseXinput = 0.0f;
private float mouseYinput = 0.0f;
//Dualshock 4
private float DS4JoyRXinput = 0.0f;
private float DS4JoyRYinput = 0.0f;
//Windows/XBOX controller
private float XBOXYoyRXinput = 0.0f;
private float XBOXYoyRYinput = 0.0f;
//*Move inputs*
private float moveXinput = 0;
private float moveYinput = 0;
//Keyboard and mouse
private float ADKeyXinput = 0;
private float WSKeyYinput = 0;
//Dualshock 4
private float DS4JoyLXinput = 0;
private float DS4JoyLYinput = 0;
//Windows/XBOX controller
private float XBOXYoyLXinput = 0.0f;
private float XBOXYoyLYinput = 0.0f;
//*Jump inputs*
private bool jumpInputPress = false;
private bool jumpInputHold = false;
private bool jumpInputRelease = false;
//Keyboard and mouse
private bool spaceInputPress = false;
private bool spaceInputHold = false;
private bool spaceInputRelease = false;
//Dualshock 4
private bool DS4CrossInputPress = false;
private bool DS4CrossInputHold = false;
private bool DS4CrossInputRelease = false;
//Windows/XBOX controller
private bool XBOXAInputPress = false;
private bool XBOXAInputHold = false;
private bool XBOXAInputRelease = false;
void Update ()
{
//*Find camera inputs*
//Find mouse inputs
mouseXinput = Input.GetAxis("Mouse X");
mouseYinput = Input.GetAxis("Mouse Y");
//Find DS4JoyR inputs
DS4JoyRXinput = Input.GetAxis("DS4JoyRX");
DS4JoyRYinput = Input.GetAxis("DS4JoyRY");
//Find XBOXJoyR inputs
//*Find move inputs*
//Find mouse inputs
ADKeyXinput = Input.GetAxis("ADKey's X");
WSKeyYinput = Input.GetAxis("WSKey's Y");
//Find DS4JoyL inputs
DS4JoyLXinput = Input.GetAxis("DS4JoyLX");
DS4JoyLYinput = Input.GetAxis("DS4JoyLY");
}
}