Advertisement
shadowx320

ControllerWarning.cs

Aug 23rd, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.40 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5.  
  6. // <summary>
  7. // Splash screen.cs
  8. // Bj Thomas
  9. // 8/20/2018
  10. // <summary>
  11.  
  12. public class ControllerWarning : ControllerManager {
  13.  
  14. public Texture2D _controllerWarningBackground; //Create slot in inspector to assign the controller warning background
  15. public Texture2D _controllerWarningText; //Create slot in inspector to assign the controller warning text message
  16. public Texture2D _controllerDetectedText; //Create slot in inspector to assign the controller detected text message
  17.  
  18. public float _controllerWarningFadeValue; //Defines the fade value of the warning text
  19. private float _controllerWarningFadeSpeed = 0.25f; //Defines the fade speed
  20. private bool _controllerConditionsMet; //Defines if the controller conditions are met for the game to continue
  21.  
  22. // Use this for initialization
  23. void Start () {
  24. _controllerWarningFadeValue = 1; //Fade value equals one on startup
  25. _controllerConditionsMet = false; //Controller condintions met is false on startup
  26. }
  27.  
  28. // Update is called once per frame
  29. void Update () {
  30. if (_controllerDetected == true) //if controller detected equals true
  31. StartCoroutine("WaitToLoadMainMenu"); //Start WaitToLoadMainMenu function
  32.  
  33. if (_controllerConditionsMet == false) //if controller condition met equals false
  34. return; //then do nothing and return
  35.  
  36. if(_controllerConditionsMet == true){ //if controller conditions met equals true
  37. _controllerWarningFadeValue -= //decrease fade value
  38. _controllerWarningFadeSpeed //by fade speed
  39. * Time.deltaTime; //times delta time
  40.  
  41. if (_controllerWarningFadeValue < 0) //if fade equals zero
  42. _controllerWarningFadeValue = 0; //then set fade value to equal zero exactly
  43.  
  44. if (_controllerWarningFadeValue == 0)
  45. {
  46. _startUpFinished = true; //Set startup finished to true
  47. SceneManager.LoadScene("MainMenu"); //load main menu scene
  48. }
  49. }
  50. }
  51.  
  52. private IEnumerator WaitToLoadMainMenu(){
  53. yield return new WaitForSeconds(2); //wait for this (x) many seconds
  54.  
  55. _controllerConditionsMet = true; //Set controller condition met to true
  56. }
  57.  
  58. private void OnGUI(){
  59. GUI.DrawTexture(new Rect(0, 0, //Draw Texture starting at 0,0
  60. Screen.width, Screen.height), //by the screen width and height
  61. _controllerWarningBackground); //draw the warning background
  62.  
  63. GUI.color = new Color(1,1,1, //GUI color is equal to 1 1 1 (rgb default)
  64. _controllerWarningFadeValue); //plus the fade value
  65.  
  66. GUI.DrawTexture(new Rect(0, 0, //Draw Texture starting at 0,0
  67. Screen.width, Screen.height), //by the screen width and height
  68. _controllerWarningText); //draw the controller warning text
  69.  
  70. if(_controllerDetected == true) //if controller detected equals true
  71. GUI.DrawTexture(new Rect(0, 0, //Draw Texture starting at 0,0
  72. Screen.width, Screen.height), //by the screen width and height
  73. _controllerDetectedText); //draw the controller detected text
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement