ControlsButtonHandler.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using UnityEngine;
  2. using System.Collections;
  3. public class ControlsButtonHandler : MonoBehaviour {
  4. private ControllerScriptCS hControllerScriptCS;
  5. private UIToggle uicControls;
  6. private ControllerScriptCS.ControlType controlType;
  7. void Start ()
  8. {
  9. hControllerScriptCS = (ControllerScriptCS)GameObject.Find("Player").GetComponent(typeof(ControllerScriptCS));
  10. uicControls = (UIToggle)this.GetComponent(typeof(UIToggle));
  11. //check which radio button is this
  12. if (this.name == "Swipe")
  13. controlType = ControllerScriptCS.ControlType.Swipe;
  14. else
  15. controlType = ControllerScriptCS.ControlType.Gyro;
  16. //check or uncheck according to type of controls currently enabled
  17. if (controlType == ControllerScriptCS.ControlType.Swipe)
  18. {
  19. if (hControllerScriptCS.isSwipeControlEnabled())
  20. uicControls.isChecked = true;
  21. else
  22. uicControls.isChecked = false;
  23. }
  24. else if (controlType == ControllerScriptCS.ControlType.Gyro)
  25. {
  26. if (!hControllerScriptCS.isSwipeControlEnabled())
  27. uicControls.isChecked = true;
  28. else
  29. uicControls.isChecked = false;
  30. }
  31. }//end of start
  32. void OnActivate(bool state)
  33. {
  34. if (state && controlType == ControllerScriptCS.ControlType.Swipe)
  35. hControllerScriptCS.toggleSwipeControls(true);
  36. else if (state && controlType == ControllerScriptCS.ControlType.Gyro)
  37. hControllerScriptCS.toggleSwipeControls(false);
  38. }//end of On Activate
  39. }