Hey there this is really cool, one question I have tho is how i could add audio ques to if i get the code wrong or if you press the button or something like that
You certainly can use this to open two doors at the same time to do so, change.... Line 13: public Transform toOpen; to.... public Transform toOpen1, toOpen2; and drag your doors into the scripts transform slots in the inspector also change the Open IEnumerator to..... IEnumerator Open () { toOpen1.Rotate(new Vector3(0,90,0),Space.World); toOpen2.Rotate(new Vector3(0,90,0),Space.World); yield Return new WaitForSeconds(4); toOpen1.Rotate(new Vector3(0,-90,0),Space.World); toOpen2.Rotate(new Vector3(0,-90,0),Space.World); } This should open both doors at the same time from the same lock. I'd also like to suggest potentially changing the toOpen variable to be an array containing both the doors, then use a for loop to iterate through that array in the Open IEnumerator and call Rotate() on each Transform before and after the yield return new WaitForSeconds(). With the respective values ofcourse. Either will work. The second is just a bit more tidy. If you'd prefer the second and have trouble implementing it yourself, let me know and I'll reply with a solution in a follow up comment.
I don’t wish to keep changing but I want it to auto change every time I reset the game... Is there a way? Otherwise I have to change it every time when i publish...
@@EdwinCreatives Indeed, Add this to your codelock script, at line 14 void Start(){ code = Random.Range(x,y).ToString(); } x being your lowest accepted value, y being the highest. ex: Random.Range(1, 9999). You can also make x and y into public int variables you can use to set as min a max from the inspector instead of the code itself.
@@aeonicsoftworks6370 Sorryyyyy... I have have another question😅 How to make a the paper change its number together with the code? Do I use back the same line?
Thanks for turorial man! Its the best one I found! Not sure if u are still active but is there a way how to show player what he pressed? If its like this u can see it only in project, not in game :/ For those who don´t want to rewrite it all: CodeLock: using System.Collections; using System.Collections.Generic; using UnityEngine; public class CodeLock : MonoBehaviour { int CodeLenght; int placeInCode; public string code = ""; public string attemptedCode; public Transform toOpen; private void Start() { CodeLenght = code.Length; } void CheckCode() { if (attemptedCode == code) { StartCoroutine(Open()); } else { Debug.Log("pica"); } } IEnumerator Open() { toOpen.Translate(new Vector3(2, 5, 10), Space.World); yield return new WaitForSeconds(60); toOpen.Translate(new Vector3(-2, -6, -10), Space.World); }
public void SetValue (string value) { placeInCode++; if (placeInCode
This should work aslong as.. Your code is the same Your crosshair(which i assume is a gameObject and is sitting at your mouse position). does not collide with the ray. Your reachRange is long enough(try making this number larger) If these are the case and its not working. Please add this to line 27... Debug.Log(hit.collider.gameObject.name); Save the project then start it up. Once its running, you are in the reach range and are looking at a gameObject with a collider the ray can collide with, you will get a debug.Log() in your console panel, Let me know what this says when your looking at the codelock. Id also suggest turning on collapse in your console window to stop your console window getting spammed by the Debug.Log(). By default its the second option in the top mounted hot bar.
To make it behave like a sliding door you can use transform.Translate() instead of transform.Rotate() to do so Replace.... toOpen.Rotate() on lines 25 and 29 with toOpen.Translate(x,y,z) x, y and z being the amount you wish to move the object in world space. I cannot give you exact numbers here but with a little tweaking I'm sure you can find the correct values. Also make sure you reverse the values on line 29.
You can indeed apply this to a chest. You could replace the door to be the top of a chest to visually display the opening of the chest. If your chest has loot, you can make the loot available to the player on successfully entering the code. I hope this helps you out and if your unsure about how to do that please let me know and ill be happy to give a hand :).
@@aeonicsoftworks6370 Thank you so much buddy for replying back means alot it would be really great actually ,because i noticed your script has a door rotation which means the only way that animation will work is by rotating the door or any object to 90 degrees, but i dont want that , because i already have my own animation for the chest so i want to apply it there but i dont know how to make it work . Anyway ill probably try it out and see if i can if not then ill make sure to contact you . Thanks again for your time and you gained a subscriber
Why does my code lock only able to type double numbers such as 11,22,33,44 and My passcode can get wrong everytime just because of this. How do I fix that?
I'm assuming you are making two calls to the set value. Make sure there is only one Controller on the main camera. Make sure the if statement at line 22 in the codelock class is the same as i have wrote. if neither of these solve your issue have a look through the controller class and make sure it is exactly the same as i wrote. Also check the entire SetValue() method in the codelock class. If these still do not fix it feel free to copy paste your code as a reply and ill look at it for you.
Hey there this is really cool, one question I have tho is how i could add audio ques to if i get the code wrong or if you press the button or something like that
Sir, I love you so so so so much. this video has super helpful!
how do you make this work with a first person camera inside a empty player object?
Great video! I'm making my first game just for fun and this was very helpful. Thanks!
Thank you for your kind words, i'm glad to have been able to help you out.
Any way to make it rotate 2 doors at the same time???
I am making 2 doors...
Should I assign the script to Parent?
You certainly can use this to open two doors at the same time
to do so, change....
Line 13: public Transform toOpen;
to....
public Transform toOpen1, toOpen2;
and drag your doors into the scripts transform slots in the inspector
also change the Open IEnumerator to.....
IEnumerator Open ()
{
toOpen1.Rotate(new Vector3(0,90,0),Space.World);
toOpen2.Rotate(new Vector3(0,90,0),Space.World);
yield Return new WaitForSeconds(4);
toOpen1.Rotate(new Vector3(0,-90,0),Space.World);
toOpen2.Rotate(new Vector3(0,-90,0),Space.World);
}
This should open both doors at the same time from the same lock. I'd also like to suggest potentially changing the toOpen variable to be an array containing both the doors, then use a for loop to iterate through that array in the Open IEnumerator and call Rotate() on each Transform before and after the yield return new WaitForSeconds(). With the respective values ofcourse.
Either will work. The second is just a bit more tidy. If you'd prefer the second and have trouble implementing it yourself, let me know and I'll reply with a solution in a follow up comment.
I don’t wish to keep changing but I want it to auto change every time I reset the game... Is there a way? Otherwise I have to change it every time when i publish...
I meant the code
@@EdwinCreatives Indeed,
Add this to your codelock script, at line 14
void Start(){
code = Random.Range(x,y).ToString();
}
x being your lowest accepted value, y being the highest.
ex: Random.Range(1, 9999).
You can also make x and y into public int variables you can use to set as min a max from the inspector instead of the code itself.
@@aeonicsoftworks6370 Sorryyyyy... I have have another question😅 How to make a the paper change its number together with the code? Do I use back the same line?
great video but i get the error CS1503: Argument 1: cannot convert from 'void' to 'string'
Can you tell me what time it is you write this line of code that throws the error?
could this have a randomly generated password or pick between a number of passwords
Thanks for turorial man! Its the best one I found! Not sure if u are still active but is there a way how to show player what he pressed? If its like this u can see it only in project, not in game :/
For those who don´t want to rewrite it all:
CodeLock:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CodeLock : MonoBehaviour
{
int CodeLenght;
int placeInCode;
public string code = "";
public string attemptedCode;
public Transform toOpen;
private void Start()
{
CodeLenght = code.Length;
}
void CheckCode()
{
if (attemptedCode == code)
{
StartCoroutine(Open());
}
else
{
Debug.Log("pica");
}
}
IEnumerator Open()
{
toOpen.Translate(new Vector3(2, 5, 10), Space.World);
yield return new WaitForSeconds(60);
toOpen.Translate(new Vector3(-2, -6, -10), Space.World);
}
public void SetValue (string value)
{
placeInCode++;
if (placeInCode
how to insert reset button?
How could I make it react to my crosshair instead of my camera? I'm trying to do this in first person and it seems difficult
This should work aslong as..
Your code is the same
Your crosshair(which i assume is a gameObject and is sitting at your mouse position). does not collide with the ray.
Your reachRange is long enough(try making this number larger)
If these are the case and its not working. Please add this to line 27...
Debug.Log(hit.collider.gameObject.name);
Save the project then start it up.
Once its running, you are in the reach range and are looking at a gameObject with a collider the ray can collide with, you will get a debug.Log() in your console panel, Let me know what this says when your looking at the codelock. Id also suggest turning on collapse in your console window to stop your console window getting spammed by the Debug.Log(). By default its the second option in the top mounted hot bar.
The crosshair should be a UI element, so just get a ray forward from the camera
How to make the door just positioning not rotate? Move to left or right . thanks
you could always use animation for that but I am struggling from the script and still able to help and happy to help.
You can also do as the video shown 2:08
To make it behave like a sliding door you can use transform.Translate() instead of transform.Rotate()
to do so Replace....
toOpen.Rotate() on lines 25 and 29
with
toOpen.Translate(x,y,z)
x, y and z being the amount you wish to move the object in world space. I cannot give you exact numbers here but with a little tweaking I'm sure you can find the correct values. Also make sure you reverse the values on line 29.
Hello Good sir i hope you doign well i was just wondering is it possible if i apply this on a chest with my own animation or i cant
You can indeed apply this to a chest. You could replace the door to be the top of a chest to visually display the opening of the chest. If your chest has loot, you can make the loot available to the player on successfully entering the code. I hope this helps you out and if your unsure about how to do that please let me know and ill be happy to give a hand :).
@@aeonicsoftworks6370 Thank you so much buddy for replying back means alot it would be really great actually ,because i noticed your script has a door rotation which means the only way that animation will work is by rotating the door or any object to 90 degrees, but i dont want that , because i already have my own animation for the chest so i want to apply it there but i dont know how to make it work . Anyway ill probably try it out and see if i can if not then ill make sure to contact you . Thanks again for your time and you gained a subscriber
it doasnt work at all for me. Nothing happens but i have no errors
same here!!
Why does my code lock only able to type double numbers such as 11,22,33,44 and My passcode can get wrong everytime just because of this. How do I fix that?
I'm assuming you are making two calls to the set value.
Make sure there is only one Controller on the main camera.
Make sure the if statement at line 22 in the codelock class is the same as i have wrote.
if neither of these solve your issue have a look through the controller class and make sure it is exactly the same as i wrote. Also check the entire SetValue() method in the codelock class.
If these still do not fix it feel free to copy paste your code as a reply and ill look at it for you.
It may be because you have Input.GetButton() instead of getbuttondown
@@2ksnakenoodles This fixed it thanks man :)
@@Lune1858 No Worries :D good to see it worked
Wait why is all green
If u watch this on a note9 and put the Video Quality on 720p48 its green
Phone problem or RUclips problem... Not the video's fault.😂😂😂
I've been trying to make a 3D keypad for days you finally solved it for me thank you!
Glad to help buddy!