SimpleActivatorMenu.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. #pragma warning disable 618
  5. namespace UnityStandardAssets.Utility
  6. {
  7. public class SimpleActivatorMenu : MonoBehaviour
  8. {
  9. // An incredibly simple menu which, when given references
  10. // to gameobjects in the scene
  11. public Text camSwitchButton;
  12. public GameObject[] objects;
  13. private int m_CurrentActiveObject;
  14. private void OnEnable()
  15. {
  16. // active object starts from first in array
  17. m_CurrentActiveObject = 0;
  18. camSwitchButton.text = objects[m_CurrentActiveObject].name;
  19. }
  20. public void NextCamera()
  21. {
  22. int nextactiveobject = m_CurrentActiveObject + 1 >= objects.Length ? 0 : m_CurrentActiveObject + 1;
  23. for (int i = 0; i < objects.Length; i++)
  24. {
  25. objects[i].SetActive(i == nextactiveobject);
  26. }
  27. m_CurrentActiveObject = nextactiveobject;
  28. camSwitchButton.text = objects[m_CurrentActiveObject].name;
  29. }
  30. }
  31. }