BackButton.cs 978 B

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