How To Make Door Unlock With Keypad In Unity By M-Unity-Developer

Поделиться
HTML-код
  • Опубликовано: 2 фев 2025
  • НаукаНаука

Комментарии • 38

  • @222مجهول
    @222مجهول 3 года назад +4

    you r great man!!!!

  • @IzzahMaisarahMohdRadzi
    @IzzahMaisarahMohdRadzi Год назад +1

    i'm doing a 1st person pov. now the keypad appears on screen no matter where the player moves as it is on canvas. if i want the keypad to be fixed on a cabinet, how to do it?

    • @m-unity-developer6823
      @m-unity-developer6823  11 месяцев назад

      Create a 3D lock game object instead of using 2D UI and then use Raycast instead to check for each button click.

    • @sitifatimah-un9fx
      @sitifatimah-un9fx 5 месяцев назад

      @@m-unity-developer6823can u do tutorial pls

  • @roshan3554
    @roshan3554 Год назад +2

    I cant move ans text to script component. Plz help

    • @svn2463
      @svn2463 Год назад +1

      public TextMeshProUGUI Ans;

    • @m-unity-developer6823
      @m-unity-developer6823  Год назад

      Use [SerializedField] while defining the UI Text variable or make the variable public.

    • @Amogussussypro
      @Amogussussypro 2 месяца назад

      @@svn2463this dont work help

    • @Notherela
      @Notherela Месяц назад

      Show "Invalid" for 2 seconds before clearing the Ans text.
      Add a delete button functionality to remove the last entered digit.
      csharp
      Copy code
      using System.Collections;
      using UnityEngine;
      using UnityEngine.UI;
      public class Keypad : MonoBehaviour
      {
      [SerializeField] private Text Ans; // Text displaying entered numbers
      [SerializeField] private Animator Door; // Animator controlling the door
      private string Answer = "123456"; // Correct keypad code
      private Coroutine invalidCoroutine; // To manage "Invalid" timeout
      public void Number(int number)
      {
      Ans.text += number.ToString();
      }
      public void Delete()
      {
      if (Ans.text.Length > 0)
      {
      Ans.text = Ans.text.Substring(0, Ans.text.Length - 1);
      }
      }
      public void Execute()
      {
      if (Ans.text == Answer)
      {
      Ans.text = "Correct";
      Door.SetBool("Open", true);
      StartCoroutine(StopDoor());
      }
      else
      {
      if (invalidCoroutine != null)
      {
      StopCoroutine(invalidCoroutine);
      }
      invalidCoroutine = StartCoroutine(ShowInvalid());
      }
      }
      private IEnumerator ShowInvalid()
      {
      Ans.text = "Invalid";
      yield return new WaitForSeconds(2);
      Ans.text = string.Empty;
      }
      private IEnumerator StopDoor()
      {
      yield return new WaitForSeconds(0.5f);
      Door.SetBool("Open", false);
      Door.enabled = false;
      }
      }
      Explanation of Changes:
      Added Delete Method: Removes the last digit if the text is not empty.
      "Invalid" Timeout:
      Created a coroutine ShowInvalid to display "Invalid" for 2 seconds and then clear the text.
      Used a Coroutine variable (invalidCoroutine) to ensure only one "Invalid" coroutine runs at a time.
      Maintained Existing Functionality: The door opens when the correct code is entered, and the animation stops after 0.5 seconds.
      UI Setup:
      Add a Delete button in your UI and link its OnClick event to the Delete method of this script.
      Ensure the keypad buttons call Number(int) with their respective values.
      You said:

  • @m-unity-developer6823
    @m-unity-developer6823  3 года назад +4

    If you guys have any query so you can ask here!

    • @InfiniteCodeSource
      @InfiniteCodeSource 2 года назад +1

      When I try to put the text into the ans it doesn’t work. Is it because I’m using text mesh pro?

    • @m-unity-developer6823
      @m-unity-developer6823  2 года назад

      @@InfiniteCodeSource Yes, you need to change the type.

    • @worldcup202-6o
      @worldcup202-6o 2 года назад +1

      @@m-unity-developer6823 How to open door with a key , if you have key

    • @sleepyminecart6182
      @sleepyminecart6182 Год назад +1

      how can i do it in 2d

    • @Patrick_games
      @Patrick_games Год назад +1

      how to do it on trigger?

  • @sarahmaharjan6934
    @sarahmaharjan6934 9 месяцев назад

    when i add the first script it shows error saying text doesnt exixt

  • @Nero-e6z
    @Nero-e6z Год назад +1

    Nice job bro

  • @arogyarijal6335
    @arogyarijal6335 Год назад +1

    How to keep the keypad in a fixed place in game mode?

  • @meltSTUDIO
    @meltSTUDIO Год назад +1

    Thanks you, its perfecto work!

  • @Garu2020
    @Garu2020 2 года назад +1

    U have done a great job

  • @1mdreams665
    @1mdreams665 2 года назад +1

    Please continue gta series

  • @davidlaslyubana3505
    @davidlaslyubana3505 3 месяца назад

    it is work for mobile game version?

  • @jyxiaa
    @jyxiaa Год назад +2

    bro took 8 years to upload his video 💀

  • @zakootagamerz
    @zakootagamerz 3 года назад +1

    nyc bro it really help me

  • @yetongggg
    @yetongggg Год назад +1

    How to restart keying in the password after answer is keyed?

    • @m-unity-developer6823
      @m-unity-developer6823  11 месяцев назад

      You can reset the text when the correct key is keyed and could change the Open boolean param to false for resetting the door state

  • @gmangman123
    @gmangman123 2 года назад +1

    you are legend dude!

  • @MEHRABRiaz
    @MEHRABRiaz Год назад +1

    thanks bro

  • @CalitoMr
    @CalitoMr 3 года назад +1

    ❤❤

  • @HellBound_101
    @HellBound_101 2 года назад +5

    What awful music 😔

    • @AlexFerguson-vg8dw
      @AlexFerguson-vg8dw Год назад

      U just a hater, these the only type of tutorial vids i can stand, none of this 4 hour shit where the first hour is them explaining how to downlod unity

    • @SadiqAuwaluSani-ds7lb
      @SadiqAuwaluSani-ds7lb 11 месяцев назад

      I no