using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
public class LockDoor : MonoBehaviour
{
public List<GameObject> buttons; // List of ButtonDoor objects associated with this lock
public Animator lockAnimator;
private void Start()
{
// Disable the lock object at the start
gameObject.SetActive(true);
}
public void FadeOut()
{
// Trigger the fade out animation in the Animator component
lockAnimator.SetTrigger("FadeOut");
}
public bool CheckButtonOrder()
{
// Check if the pressed buttons match the correct order
for (int i = 0; i < buttons.Count; i++)
{
ButtonDoor button = buttons[i].GetComponent<ButtonDoor>();
// If the button order is incorrect, return false
if (button.buttonNumber != i + 1)
{
return false;
}
}
return true;
}
}
#Lock door portal
1 messages · Page 1 of 1 (latest)
I think I'm doing good so far, but not very much because I don't know what works or is not working to make it lick a locked door and pressed a button or more in correct order to make it open
lemme get the video
here I am trying to do this whole lock unlocks thing over the portal door and you have to press the buttons in correct order (like 1,2,3,4 or 1,4,2,3 based on the line of the buttons) but I nothing seems to be working and even when i press the wrong order, the buttons won't go up
should i explain more?
well each button has their own List of sequences ?
cause the sequence should probably be stored on the door itself
buttons should only send to the linked door which button/number it represents
so button Reference the door that has sequence, when TriggerEnter happens send its value stored to the door for processing
for example , line 27-39 logic goes on door, same for player 2 ig
inside butonDoor doorScript.pressedButtons.Add(buttonNumber);
do you know what I mean?
so shoudl i move it over to the doorlock script?
yup
also refrain from using GameObject.Find its very slow, and error prone
always link inside the inspector when possible
if not possible, then you store a variable and assign in Awake FindGameObjectByTag
yet one question... where in the line part in the lockdoorscript should i put it?
probably a public method in which you pass the button's int for buttonNumber
something for example like public void ButtonPressed(int buttonValue)
then call that from the ButtonDoor script
only this
should be inside the Button Script
but you have to call ButtonPressed instead of pressedButtons.Add(buttonNumber
but you need to move pressedButtons.Add(buttonNumber) to the doorLock script also inside ButtonPressed
I would probably put a check though to make sure you don't add it multiple times from the same button
like this?
multiple times?
if you enter trigger of same button then the same number/button will be added
but I don't haveoh
also ResetButtonStates should be underlined red for now same with the lists since I assume you did not move those
why is the IDE not highlighting red
idk
Visual Studio guide
If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
make sure its configured or regen project files
this is resetbuttonstates
but isn't this inside another script
is that the cause?
it should be underlined red if ResetButtonStates is defined inside ButtonDoor
but you are trying to use it inside doorlock script
idk, this is when the pressed buttons goes back to the unpressed image
yeah I didn't get what you're saying there
You cannot do this
it should be underlined Red
hence why its White not Yellow inside your other script
it should be underlined red becuase its not found
this should say Assembly CSsharp up here
make sure to fix this issue first
oh you're on mac..
at very least you should be on VS2022 like it says..
but also VS is getting scrapped officially in August . Gotta start using VSCode soon
huh?
Visual Studio is going bye bye for macos
anyway for now, download 2022 and configure it as follows
https://learn.microsoft.com/en-us/visualstudio/gamedev/unity/get-started/getting-started-with-visual-studio-tools-for-unity?pivots=macos
scroll down to unity
uhh..... I don't know where to find it
oh its not here for mac
oh...
you will find it after install
Visual Studio for Mac > Extensions > Game Development
but 2022 version
is it stuck?
it's been like 5 minutes
Install tools
should be small
not the whole xCode
just Xcode command line tools
ok, it is down loading and downloaded now (and i presed on done)
did you follow the rest of the steps
is that 2022?
I don't know
no
do that first,make sure it reads the new editor
what's this?
well this means you have compile errors, like i said earlier
it just your editor wasn't highlighting them
Enter Safe Mode
I did have 7 red erroes when I saved the scripts
yes
its probably saying things like ResetButtons is missing definition
go to the preferences first, see if editor shows up
how can i go in preferences even though I didn't go in unity yet
click Enter Safe mode it should still be able to let u go in preferences
uhhh... i will never be used to this, I even can't see the draw images
the assets aren't important they are disabled because the editor cant compile with errors
go in the External Tools - Preferences again
where can i se external tools?
ok good
did you do this
You can verify the installation in the Visual Studio for Mac > Extensions > Game Development menu. Visual Studio for Mac Tools for Unity should be enabled.
it should be fine though since you can see now it says VS 17 in unity
do i go in visual studio first?
just double check
yeah its in VS
on the topbar where it says Visualstudio for Mac
I cannot find unity
found it
does it say installed?
ok good
close vs go back to External Tools, click Regen Project Files
then open script from unity
in visual studio?
unity
great it should be working now
double click one of the scripts with errors
7 errors
there we go
now its a smart editor
so you not see why these errors are there?
all this stuff is inside DoorButton
it needs to be moved to doorlock script
the whole public void ButtonPressed?
no, the lists which you are trying to use
it's in lockdoor
why do you. think pressedButtons is red?
aka missing..
if you moved it from ButtonDoor to LockDoor, you have to move everything else
the lists
this is making more confusion because you are using AI to write this code
so you don't know your own code
so the whole thing whill be moved to lockdoor?
jesus..no.
just the Lists
like this?
pressedbuttons should be <ButtonDoor> type
and then should have another one for List<int> currentSequence or something
currentSequence?
this will be the one you will use to do the compare
is this good?
no
but what about the rest of the red underlines?
you stil didnt add pressedButtons as List<ButtonDoor>
why would you write that one like that when the others are not written like that
what?
obviously its written wrong, look at the red underline
you haven't given it a name?
you have to new() private List or arrays, or they give Null Reference when you try to use it
well if you weren't stubborn to learn basic c# before doing a game
the chatbot doesn't teach you basics
List<ButtonDoor> pressedButtons = new();
public List<int> correctOrder = new();
List<int> currentSequence = new();```
you're probably using older version of Unity ?
just add List next to it then
new List<int>()
new List<ButtonDoor>()
code spoon feed but i g2g in 10 mins
public void ButtonPressed(ButtonDoor button)
{
if (pressedButtons.Contains(button) == false)
{
currentSequence.Add(button.ButtonNumber);
pressedButtons.Add(button);
}
if (currentSequence.Count == correctOrder.Count)
{
if(currentSequence.SequenceEqual(correctOrder))
{
//stuff when sequence correct?
}
else
{
//other stuff if not?
}
for (int i = 0; i < pressedButtons.Count; i++)
{
pressedButtons[i].ResetButton();
}
pressedButtons.Clear();
currentSequence.Clear();
}
}```
are you going to go somewhere?
yes gotta go to work.
Anyway try to understand what I wrote its very basic,
ButtonNumber should be the integer inside the ButtonDoor
idk what u called it so i called that
just make sure its public
ResetButton()
is basically
public void ResetButtonStates()
{
// Reset pressed buttons and change image back to normal state
GetComponent<SpriteRenderer>().sprite = normalButtonImage;
}```
or whatever else you need to do for the button to reset
it still have the red underline
because you don't have such method inside ButtonDoor script
i told you already what its supposed to be instead
you have to try to adapt what I sent to your code, don't just paste it blindly
and do you have ResetButton() inside ButtonDoor ?
alrighty
good luck at your work
haha thanks!
your welcome
tell me when you feel like it
huh ?
that you feel like you have time with this?
ok
yeah
so whats the problem?
haven't we been discussion about it here?
idk how you left it off
we left it off right here
ok so change the method to what it needed to be
I give you pretty much the whole outline and some code on it
and here we go, I did fixed it and no more red underlines
so what do you have so far
hang on
https://gdl.space/uhebulinez.cpp
https://gdl.space/ohawodawin.cpp
I came so far in this, yet i am kinda struggling with this whole that the buttons pressed in order (1 or more) to open the locked door and if pressed in wrong order (reset to the unpressed button imags and do over)
why did you change the script ?
or why is this here
CheckButtonOrder
you still didnt put anything where the comments are
put Debug.Log to make sure the lists are indeed increasing
what do you mean why i changed the script? I didn't changed anything
ok so time to debug the ButtonPressed method and making sure everything is doing what it supposed to
ok
gotta learn how to debug better values
Debug.Log($"{button.name} was passed. {pressedButtons.Count}");
what am i looking at
there we no logs in console
where did you put the log in the code
over there
you are not seeing the logs in the editor?
then its not running
find out why
hmmm... good question
but why though?
you tell me why
I don't even get it
You have to call the method
there is nothing to be confused on
why are you sending me this
You have to call ButtonPressed from the ButtonDoor script
how can i call it?
haven't you done this already many times..
dont ask such obvious things
make a reference and call the method..
same way you did it in all the other scripts you are using
I am mostly on forgetting things because of how forgetful I am (becaus eof so much stuff going on and in real life), I just don't get what I am doing wrong
in order for a method to run, you have to call it..
even though it is calling the buttondoor script?
its not calling ButtonDoor script
ButtonDoor is the Type being passed in via the method
called "button"
oh
this why when this method is called, you can pass the ButtonDoor itself thats calling it
in the ButtonDoor you have to call this method from the TriggerEnter
why are you screenshotting this
you already know what to do
call the method from here
make a reference
I don't know I can call the method from another script, my head is literally spinning around and hurting
then take a break and take a few steps back, remember how you made references in other scripts
read this if you're lost
gamedev takes a lot of brain processing, if you have other stuff going on, take break, get back to it when you're in a more comfortable time
As you get more complex mechanics this is whats gonna happen, no way around that and no one is going to be spoon feeding you the whole time.
[serialized] is a part of referencing?
since I am mostly on with gamedesigning but wanting to move the project forward. and sometimes when things doesn't work with me not knowing why, I can get easily sad
don't get so worked up, it takes patience and its mostly problem solving
the problems feel overwhelming when we lack knowledge to available solution (comes with time and experience)
and no, SerializeField
that is part of Referencing yes
its used to be able to ASSIGN a component in that FIELD
assigning is the same as doing = in the code
when you do it inside the Unity inspector then its the same thing
its doing= behind the scenes
public MyScript theName; // this only declares a variable. Its not assigned until inspector drag n drop
is the same as
[SerializeField] private MyScript theName; // this only declares a variable. Its not assigned until inspector drag n drop
they both show up in the inspector
oh... even sometimes I don't get the meanings of some sentences like "call the method" or "make a reference" sometimes it's confusing for me of the meaning and can be complex for me to understand
what helped me in the beginning is searching those things, there is usually explenations
Method/Function does something
so "calling" it means do something
if someone speaks to you on the phone and says "Go get milk"
thats calling a method
oh...
you then go get the milk
so I'm like supposed to write something call the method like calling the ButtonPressed?
the same way Door script is calling reset method on button
you need method to tell from the button "DoorScript, I was called. Here is my info "
because the method has (DoorScript) when you wrote it
you can pass the doorbutton itself(script) to the door
by passing means you're going from one place to another, like visiting someone's house
yet... I am confused on why ButtonDoor wouldn't be called
ButtonPressed ?
the Button has to call that Method
but its inside of DoorScript
hence why we make a **Reference **
Reference is like a Contact on a phone or address book,
doorscript contacting the button script?
other way around
button script contacting doorscript?
yes
doorscript is like the movies
in order to get in, you need to show your ticket
ButtonScript is the ticket you send to Door
because each Button has their own info. In this case a Number
start small
make the reference First
one step at time
so... it should have the lockdoor script name for it to call?
not sure why you put it in < > though
do you see how the ones above are written ? ?
isn't it that way so it can call the script?
do you see above?
the exact same thing
these are literally the same things you're going to be doing 70% of the time
so no idea why you wrote it like that..
if you don't write it yourself and let the AI do it you're never gonna learn
ok but why is it int ?
you did the same mistake as last time
in the other Thread
its not complicated
Type NameOfVariable
We went over this on the Fade screen thread do you not remember ?
I don't remember
well luckly the magic of the internet the thread is still there
look over it and see why thats written wrong
you have to learn this stuff
(if you want to make this project)
trying to find that
idk where to find it. should it be image?
you there? doing something?
just change the type of the declared vairable lol
its not diffcult
it should not be an int
why would DoorScript be a number
com on are you forreal right now?
I literally said, look the ones above and how they were written and you did something completly different..
Look how these are written
its 3 things
public Type variableName
idk how much simpler i can explain tbh
its more frustrating that you did this already
Why did it take this long..
k. anyway change the name pressedButtons is not a good name for it
its not a pressedButtons
buttonpressed?
my mind is slow on processing things a lot, even in real life
public LockDoor lockDoor
keep it clear what it is
anyway. now that you have the reference
simply call the method we mentioned before, inside TriggerEnter
ButtonPressed is the method
it should not be the name of the variable.
ok, so I hsould write more?
yup
it wants to know which ButtonDoor is calling it
well it wants the type ButtonDoor
so since this script is the ButtonDoor
we put this
this means "This current script"
its a special keyword
lemme check
did you drag n drop the Script LockDoor in the LockDoor field
prob not
each button needs it
it do kinda look alright
the buttons reset. thats good
that means its reading them / correct amounts
just implement now whatever needs to happen if sequence match and test if that works
thats how many buttons are being added
it seems to be working fine, except for tht even thought hey do correct order, the pressed images wouldn't stay there, and the doorlock doesn't open
ok gotta make the logic for reset only happen when its not correct order
put that part of the code in the else statement of the SequenceEquals part
show the new code after that
After you put that in
logic?
why are you showing me ButtonDoor
we're past that
the issue is inside the Door script
again, think for a moment where that opening door script is being controlled from.
hmmmmmmm... well if you did the correct order, the lock door will open by doing the opening animation and the buttons are still pressed https://gdl.space/lofobuyehi.cs
this isn't magic
things need to be coded in
obviously
if (currentSequence.SequenceEqual(correctOrder))
{
//stuff when sequence correct?
}
else
{
//other stuff if not?
}```
these comments are there its not doing anything
how else do expect something to happen by magic ?
I put those comments there to give you a hint what to put there
its a basic if statement. You are using these everywhere, think for a moment what goes there
oh
not much i added in but,
but i highly doubt about because what if there would be multiple locks on different doors
I mean, you already kinda made references
do the same thing
what type is Lock? what are you doing with it
make the field in the inspector so you can link specific Lock
just like you did with the Button for linking DoorScript
You see its pretty much doing the same stuff over and over..
Make a reference, assign the reference, and use the reference
rinse and repeat
thats A reference
not the one you need
but the concept is the same..
Ask yourself what is Lock?
the type
it is the locked door that is blocking the doort portal and is assigned to the buttons
okay but what do you need from Lock
that if the buttons are pressed in correct order, it's doing the open animation and disappear which the player can enter, but if the buttons are pressed in wrong order, then the door won't open and do the animation and you have to do over again
great so start with the first part
You need 2 parts to that
Animator first
oh yeah, the animator
I do have the animation
I mean I have the door lock opening animation
alr so you need call that animation from the script in the sequence match
sequence march?
you mean the lockdoor?
in the lockdoor script
ok
but yet I somehow can put the animation in there
dont you have the animation inside the Animator
you don't need Animation
you need Animator
lookslike you have one already
what is that one for ?
but if i use animator, then it will just do the door opening animation immediatly when i start the game
why is that
don't you have a trigger for it ?
where can i find the trigger inside Animator?
Trigger is type of transition condition of Animator
anyway you can use anything really
bool
ok just add an empty state , right click it set as default starting layer
if you right click in that animator area you can add a new state
empty
you need an empty one, right click the empty one and set as Default starting clip
then create transition from empty to opening clip
open is empty?
right click on it and create transition from that to the animation you want
door portal back no longer have the animation and now open have the animation
ohh.
thats fine then
so just select the transition arrow
and make sure its correct condition
like this?
exit time should be unchecked or it will automatically transition
i showed you the page how to add transition condition
ok, i unchecked the has exit time
alr
so do the reset. you have to call that from the script now
you should know where it goes
what is FadeOut method do
the for loop and the Clear lists go in the else statement if you only want to reset if its not correct
for loop is still wrong
what loop and clear lists? (but you said clear lists goes in the else statement
the loop thats in the code you sent
the for loop
I didn't say the list is wrong
and those are the only two that say clear, obviously those what Im talking about
jesus..
you said else statement that i thought you meant "else" as if i'm supposed to put loop and the clears lists in there
no
i said put those things in the else statement
you first put the lists only then put the for loop only
🤷♂️ not sure where the miscommunication is
how do i put lists only and the loop only in one else statement?
do you not know what .Clear and ResetButtons loop are doing ?
do you know what else statement is doing ? i wrote it in the comment before in code
look at the code for moment
and think about where those pieces need to go
what am i suppsoed to put there? if I can't put what i wrote there, what is it i'm supposed to put there instead and how do i put lists of clears in there? this is so confusing
and the way you said that there before made me thought that i'm supposed to put them in the else statement
Yes
ur supposed to but you didn't put all of it
you kept switching between both
that took literally an hour and half
it's just the fact when you said "no" made me thought i did it wrong and that i'm not supposed to put them there
yea because you only put one thing lol
also its inverted
you're clearing the list before the loop..
this will break everything
it wont have any buttons to Reset on
yes. Code runs each line top to bottom
then re-read the rest of what I said it might make sense
what do you think?

woah, it sure lasted much longer, like 6 hourse
yes you have to take time to at least have more basics prepared, before doing such complex mechanics