SimpleActivatorMenu.cs 1.0 KB

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