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?
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:
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
you r great man!!!!
Thanks ❤
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?
Create a 3D lock game object instead of using 2D UI and then use Raycast instead to check for each button click.
@@m-unity-developer6823can u do tutorial pls
I cant move ans text to script component. Plz help
public TextMeshProUGUI Ans;
Use [SerializedField] while defining the UI Text variable or make the variable public.
@@svn2463this dont work help
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:
If you guys have any query so you can ask here!
When I try to put the text into the ans it doesn’t work. Is it because I’m using text mesh pro?
@@InfiniteCodeSource Yes, you need to change the type.
@@m-unity-developer6823 How to open door with a key , if you have key
how can i do it in 2d
how to do it on trigger?
when i add the first script it shows error saying text doesnt exixt
Nice job bro
How to keep the keypad in a fixed place in game mode?
It will be in fixed place since the graphics are rendered on canvas
Thanks you, its perfecto work!
U have done a great job
Please continue gta series
it is work for mobile game version?
bro took 8 years to upload his video 💀
nyc bro it really help me
How to restart keying in the password after answer is keyed?
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
you are legend dude!
thanks bro
❤❤
What awful music 😔
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
I no