Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- // <summary>
- // Splash screen.cs
- // Bj Thomas
- // 8/15/2018
- // <summary>
- public class ControllerManager : MonoBehaviour {
- public Texture2D _controllerNotDetected; //Creates slot in inspector to assign controller not detected warning test
- public bool _pS4Controller; //Creates bool for when a ps4 controller is connected
- public bool _XboxController; //Creates bool for when a xbox controller is connected
- public bool _controllerDetected; //Creates bool for when a controller is connected
- public static bool _startUpFinished; //Creates bool for when start up is finished
- private void Awake(){
- _pS4Controller = false; //PS4 controller is false on awake
- _XboxController = false; //Xbox controller is false on awake
- _controllerDetected = false; //controller is false on awake
- }
- // Use this for initialization
- void Start () {
- DontDestroyOnLoad(this); //Don't destroy this gameobject when loading a new scene
- }
- // Update is called once per frame
- void Update () {
- }
- void LateUpdate(){
- string[] _joyStickNames = Input.GetJoystickNames(); //_joyStickNames equals get joystick names from inbuilt input
- for(int _js = 0; _js < _joyStickNames.Length; _js++){ //increase counter _js based on joystick names length
- if(_joyStickNames [_js].Length == 19){ //if joystick name equals code 19
- _pS4Controller = true; //set ps4 controller to true
- _controllerDetected = true; //set a controller detected to true
- }
- if(_joyStickNames [_js].Length == 33){ //if joystick name equals code 33
- _XboxController = true; //set xbox controller to true
- _controllerDetected = true; //set a controller detected to true
- }
- if (_joyStickNames[_js].Length != 0) //if joystick names does not equal 0
- return; //then do nothing and return
- if (string.IsNullOrEmpty(_joyStickNames[_js])) //if string is null/empty ie no controller detected
- _controllerDetected = false; //then set controller detected to false
- }
- }
- private void OnGUE(){
- if (_startUpFinished == false) //if start up finished equals false
- return; //then do nothing and return
- if(_controllerDetected == true) //if controller detected equals true
- return; //then do nothing and return
- if (_controllerDetected == false) //if controller detected equals false
- GUI.DrawTexture(new Rect( //Draw texture
- 0, 0, //at this position
- Screen.width, Screen.height), //by these dimensions
- _controllerNotDetected); //draw the controller not detected texture
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement