Advertisement
shadowx320

ControllerManager.cs

Aug 23rd, 2018
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.86 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. // <summary>
  6. // Splash screen.cs
  7. // Bj Thomas
  8. // 8/15/2018
  9. // <summary>
  10.  
  11. public class ControllerManager : MonoBehaviour {
  12.  
  13. public Texture2D _controllerNotDetected; //Creates slot in inspector to assign controller not detected warning test
  14.  
  15. public bool _pS4Controller; //Creates bool for when a ps4 controller is connected
  16. public bool _XboxController; //Creates bool for when a xbox controller is connected
  17. public bool _controllerDetected; //Creates bool for when a controller is connected
  18.  
  19. public static bool _startUpFinished; //Creates bool for when start up is finished
  20.  
  21. private void Awake(){
  22. _pS4Controller = false; //PS4 controller is false on awake
  23. _XboxController = false; //Xbox controller is false on awake
  24. _controllerDetected = false; //controller is false on awake
  25. }
  26.  
  27. // Use this for initialization
  28. void Start () {
  29. DontDestroyOnLoad(this); //Don't destroy this gameobject when loading a new scene
  30. }
  31.  
  32. // Update is called once per frame
  33. void Update () {
  34.  
  35. }
  36.  
  37. void LateUpdate(){
  38. string[] _joyStickNames = Input.GetJoystickNames(); //_joyStickNames equals get joystick names from inbuilt input
  39.  
  40. for(int _js = 0; _js < _joyStickNames.Length; _js++){ //increase counter _js based on joystick names length
  41. if(_joyStickNames [_js].Length == 19){ //if joystick name equals code 19
  42. _pS4Controller = true; //set ps4 controller to true
  43. _controllerDetected = true; //set a controller detected to true
  44. }
  45.  
  46. if(_joyStickNames [_js].Length == 33){ //if joystick name equals code 33
  47. _XboxController = true; //set xbox controller to true
  48. _controllerDetected = true; //set a controller detected to true
  49. }
  50.  
  51. if (_joyStickNames[_js].Length != 0) //if joystick names does not equal 0
  52. return; //then do nothing and return
  53.  
  54. if (string.IsNullOrEmpty(_joyStickNames[_js])) //if string is null/empty ie no controller detected
  55. _controllerDetected = false; //then set controller detected to false
  56. }
  57. }
  58.  
  59. private void OnGUE(){
  60. if (_startUpFinished == false) //if start up finished equals false
  61. return; //then do nothing and return
  62.  
  63. if(_controllerDetected == true) //if controller detected equals true
  64. return; //then do nothing and return
  65.  
  66. if (_controllerDetected == false) //if controller detected equals false
  67. GUI.DrawTexture(new Rect( //Draw texture
  68. 0, 0, //at this position
  69. Screen.width, Screen.height), //by these dimensions
  70. _controllerNotDetected); //draw the controller not detected texture
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement