[text] aa

Viewer

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.SceneManagement;
  6.  
  7. public class E2S : MonoBehaviour
  8. {
  9.     public string targetScene; // Nama scene yang akan dituju saat tombol (esc) ditekan
  10.     public GameObject targetPanel; // Panel yang akan ditampilkan/sembunyikan saat tombol (esc) ditekan
  11.     public bool switchToScene; // Apakah ingin beralih ke scene atau hanya menampilkan/sembunyikan panel
  12.  
  13.     void Update()
  14.     {
  15.         if (Input.GetKeyDown(KeyCode.Escape))
  16.         {
  17.             SwitchSceneOrPanel();
  18.         }
  19.     }
  20.  
  21.     void SwitchSceneOrPanel()
  22.     {
  23.         if (switchToScene)
  24.         {
  25.             SceneManager.LoadScene(targetScene);
  26.         }
  27.         else
  28.         {
  29.             if (targetPanel != null)
  30.             {
  31.                 targetPanel.SetActive(!targetPanel.activeSelf); 
  32.             }
  33.         }
  34.     }
  35. }

Editor

You can edit this paste and save as new:


File Description
  • aa
  • Paste Code
  • 29 Apr-2024
  • 937 Bytes
You can Share it: