You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.0 KiB

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