BackButton.cs 894 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using UnityEngine;
  2. using UnityEngine.SceneManagement;
  3. namespace Unity.WebRTC.Samples
  4. {
  5. internal class BackButton : MonoBehaviour
  6. {
  7. [SerializeField]
  8. GameObject m_BackButton;
  9. public GameObject backButton
  10. {
  11. get => m_BackButton;
  12. set => m_BackButton = value;
  13. }
  14. void Start()
  15. {
  16. if (Application.CanStreamedLevelBeLoaded("Menu"))
  17. {
  18. m_BackButton.SetActive(true);
  19. }
  20. }
  21. void Update()
  22. {
  23. if (Input.GetKeyDown(KeyCode.Escape))
  24. {
  25. BackButtonPressed();
  26. }
  27. }
  28. public void BackButtonPressed()
  29. {
  30. if (Application.CanStreamedLevelBeLoaded("Menu"))
  31. {
  32. SceneManager.LoadScene("Menu", LoadSceneMode.Single);
  33. }
  34. }
  35. }
  36. }