CameraSwitch.cs 682 B

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. public class CameraSwitch : MonoBehaviour
  5. {
  6. public GameObject[] objects;
  7. public Text text;
  8. private int m_CurrentActiveObject;
  9. private void OnEnable()
  10. {
  11. text.text = objects[m_CurrentActiveObject].name;
  12. }
  13. public void NextCamera()
  14. {
  15. int nextactiveobject = m_CurrentActiveObject + 1 >= objects.Length ? 0 : m_CurrentActiveObject + 1;
  16. for (int i = 0; i < objects.Length; i++)
  17. {
  18. objects[i].SetActive(i == nextactiveobject);
  19. }
  20. m_CurrentActiveObject = nextactiveobject;
  21. text.text = objects[m_CurrentActiveObject].name;
  22. }
  23. }