Advertisement
MatiGe

Code Entry Manager

May 3rd, 2025
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using TMPro;
  4. using UnityEngine.SceneManagement;
  5.  
  6. public class CodeEntryManager : MonoBehaviour
  7. {
  8.     public InputField codeInputField;
  9.     public Button submitButton;
  10.     public string correctCode = "TESTCODE"; // **Important: Replace with a temporary test code**
  11.     public string nextSceneName = "GameScene"; // Assuming your game scene is named "GameScene"
  12.  
  13.     void Start()
  14.     {
  15.         if (codeInputField == null || submitButton == null)
  16.         {
  17.             Debug.LogError("One or more UI elements are not assigned in the Inspector!");
  18.             enabled = false;
  19.             return;
  20.         }
  21.  
  22.         submitButton.onClick.AddListener(CheckCode);
  23.     }
  24.  
  25.     void CheckCode()
  26.     {
  27.         if (codeInputField.text == correctCode)
  28.         {
  29.             Invoke("LoadNextScene", 1f);
  30.         }
  31.         else
  32.         {
  33.             codeInputField.text = "";
  34.         }
  35.     }
  36.  
  37.     void LoadNextScene()
  38.     {
  39.         SceneManager.LoadScene(nextSceneName);
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement