#Lock door portal

1 messages · Page 1 of 1 (latest)

light crow
#
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;
    }
}
#

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

dark nacelle
#

what exactly is the issue , its unclear ?

#

what are you trying to do

light crow
#

lemme get the video

light crow
#

should i explain more?

dark nacelle
#

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?

light crow
#

so shoudl i move it over to the doorlock script?

dark nacelle
#

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

light crow
#

yet one question... where in the line part in the lockdoorscript should i put it?

dark nacelle
#

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

light crow
#

should i also put the whole player thing in there?

#

like this?

dark nacelle
#

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

dark nacelle
light crow
#

but I don't haveoh

dark nacelle
#

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

light crow
#

idk

dark nacelle
#

did you not do this
!vs

#

!vs

true kettleBOT
#
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)

dark nacelle
#

make sure its configured or regen project files

light crow
#

this is resetbuttonstates

dark nacelle
light crow
#

oh, but well it's black text, but not underline red

#

i think because of this?

light crow
dark nacelle
#

but you are trying to use it inside doorlock script

light crow
#

idk, this is when the pressed buttons goes back to the unpressed image

dark nacelle
#

I get it

#

you're not understanding what im saying

light crow
dark nacelle
#

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

light crow
dark nacelle
#

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

light crow
#

huh?

dark nacelle
#

Visual Studio is going bye bye for macos

light crow
#

ok

#

hmm... should i pick some?

dark nacelle
light crow
#

uhh..... I don't know where to find it

dark nacelle
#

oh its not here for mac

light crow
#

oh...

dark nacelle
#

you will find it after install

#

Visual Studio for Mac > Extensions > Game Development

#

but 2022 version

light crow
#

is it stuck?

dark nacelle
#

give it a few mins

light crow
#

it's been like 5 minutes

light crow
dark nacelle
#

should be small

#

not the whole xCode

#

just Xcode command line tools

light crow
light crow
dark nacelle
light crow
#

I don't know

dark nacelle
#

how do you not know , its ur pc lol

#

did restart unity when u installed vs2022?

light crow
#

no

dark nacelle
#

do that first,make sure it reads the new editor

light crow
#

what's this?

dark nacelle
#

it just your editor wasn't highlighting them

#

Enter Safe Mode

light crow
#

I did have 7 red erroes when I saved the scripts

dark nacelle
#

yes

#

its probably saying things like ResetButtons is missing definition

#

go to the preferences first, see if editor shows up

light crow
#

how can i go in preferences even though I didn't go in unity yet

dark nacelle
#

click Enter Safe mode it should still be able to let u go in preferences

light crow
#

uhhh... i will never be used to this, I even can't see the draw images

dark nacelle
#

go in the External Tools - Preferences again

light crow
light crow
dark nacelle
#

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

dark nacelle
#

just double check

#

yeah its in VS

#

on the topbar where it says Visualstudio for Mac

light crow
dark nacelle
#

actually no need

#

click here

light crow
dark nacelle
#

find Unity

light crow
#

I cannot find unity

dark nacelle
#

u dont have this ?

light crow
#

found it

dark nacelle
#

does it say installed?

light crow
dark nacelle
#

ok good

#

close vs go back to External Tools, click Regen Project Files

#

then open script from unity

dark nacelle
#

unity

light crow
dark nacelle
#

double click one of the scripts with errors

light crow
#

7 errors

dark nacelle
#

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

light crow
#

the whole public void ButtonPressed?

dark nacelle
#

no, the lists which you are trying to use

light crow
#

it's in lockdoor

dark nacelle
#

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

light crow
dark nacelle
#

just the Lists

light crow
#

like this?

dark nacelle
#

pressedbuttons should be <ButtonDoor> type

#

and then should have another one for List<int> currentSequence or something

light crow
#

currentSequence?

dark nacelle
light crow
light crow
dark nacelle
#

no

light crow
#

but what about the rest of the red underlines?

dark nacelle
#

you stil didnt add pressedButtons as List<ButtonDoor>

light crow
dark nacelle
#

why would you write that one like that when the others are not written like that

light crow
#

what?

dark nacelle
#

obviously its written wrong, look at the red underline

#

you haven't given it a name?

light crow
dark nacelle
#

you have to new() private List or arrays, or they give Null Reference when you try to use it

light crow
#

new()?

#

this is getting confusing for me

dark nacelle
#

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();```
light crow
dark nacelle
#

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();
     }
 }```
light crow
#

are you going to go somewhere?

dark nacelle
#

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

light crow
#

it still have the red underline

dark nacelle
#

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 ?

light crow
#

hang on, fixed it

#

no more red underlines

#

we might continue this tomorrow

dark nacelle
#

alrighty

light crow
#

good luck at your work

dark nacelle
#

haha thanks!

light crow
#

your welcome

light crow
dark nacelle
light crow
dark nacelle
light crow
#

yeah

dark nacelle
light crow
#

haven't we been discussion about it here?

dark nacelle
#

idk how you left it off

light crow
dark nacelle
#

ok so change the method to what it needed to be

#

I give you pretty much the whole outline and some code on it

light crow
dark nacelle
#

so what do you have so far

light crow
#

hang on

dark nacelle
#

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

light crow
dark nacelle
#

k well you don't nee CheckButtonOrder method

#

as SequenceEquals does that already

light crow
#

ok

#

deleted the checkbuttonorder

dark nacelle
#

ok so time to debug the ButtonPressed method and making sure everything is doing what it supposed to

light crow
dark nacelle
#

Debug.Log($"{button.name} was passed. {pressedButtons.Count}");

light crow
dark nacelle
light crow
#

hang on, wrong video

dark nacelle
#

what does the log say

light crow
dark nacelle
light crow
dark nacelle
#

then its not running

#

find out why

light crow
#

hmmm... good question

dark nacelle
#

from buttondoor

light crow
#

but why though?

dark nacelle
light crow
dark nacelle
#

there is nothing to be confused on

light crow
dark nacelle
#

why are you sending me this

#

You have to call ButtonPressed from the ButtonDoor script

light crow
#

how can i call it?

dark nacelle
#

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

light crow
#

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

dark nacelle
light crow
dark nacelle
#

its not calling ButtonDoor script

#

ButtonDoor is the Type being passed in via the method

#

called "button"

light crow
#

oh

dark nacelle
#

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

light crow
dark nacelle
#

why are you screenshotting this

#

you already know what to do

#

call the method from here

#

make a reference

light crow
#

I don't know I can call the method from another script, my head is literally spinning around and hurting

dark nacelle
#

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.

light crow
#

[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

dark nacelle
#

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)

dark nacelle
#

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

light crow
#

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

dark nacelle
#

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

light crow
#

oh...

dark nacelle
#

you then go get the milk

light crow
#

so I'm like supposed to write something call the method like calling the ButtonPressed?

dark nacelle
#

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

light crow
dark nacelle
#

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,

light crow
#

doorscript contacting the button script?

dark nacelle
#

other way around

light crow
#

button script contacting doorscript?

dark nacelle
#

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

light crow
#

so... it should have the lockdoor script name for it to call?

dark nacelle
#

not sure why you put it in < > though

#

do you see how the ones above are written ? ?

light crow
#

isn't it that way so it can call the script?

dark nacelle
#

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

light crow
dark nacelle
#

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 ?

light crow
#

I don't remember

dark nacelle
#

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)

light crow
#

trying to find that

#

idk where to find it. should it be image?

#

you there? doing something?

dark nacelle
#

its not diffcult

#

it should not be an int

#

why would DoorScript be a number

dark nacelle
#

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

dark nacelle
#

Why did it take this long..

#

k. anyway change the name pressedButtons is not a good name for it

#

its not a pressedButtons

light crow
#

buttonpressed?

light crow
dark nacelle
#

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.

light crow
#

ok, so I hsould write more?

dark nacelle
#

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

light crow
#

Seems like there's soemthing wrong with that part

dark nacelle
#

i went on a whole podium speech about it before..

light crow
#

lemme check

dark nacelle
#

did you drag n drop the Script LockDoor in the LockDoor field

#

prob not

#

each button needs it

light crow
dark nacelle
#

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

light crow
#

I don't know what the "0" is for

#

oh wait, that is for element

dark nacelle
#

thats how many buttons are being added

light crow
dark nacelle
#

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

light crow
dark nacelle
#

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.

light crow
#

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

dark nacelle
#

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

light crow
#

oh

light crow
#

not much i added in but,

#

but i highly doubt about because what if there would be multiple locks on different doors

dark nacelle
#

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

light crow
dark nacelle
#

not the one you need

#

but the concept is the same..

#

Ask yourself what is Lock?

#

the type

light crow
dark nacelle
light crow
# dark nacelle 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

dark nacelle
#

You need 2 parts to that

#

Animator first

light crow
#

oh yeah, the animator

#

I do have the animation

#

I mean I have the door lock opening animation

dark nacelle
light crow
#

sequence march?

dark nacelle
#

i said Match

#

as in Sequence Equals

light crow
#

oh, Equals

dark nacelle
#

ok

#

you put this in Door?

light crow
#

you mean the lockdoor?

dark nacelle
#

which script did you put that line

#

that screenshots provides no context

light crow
#

in the lockdoor script

dark nacelle
#

ok

light crow
#

but yet I somehow can put the animation in there

dark nacelle
#

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 ?

light crow
#

for the lock door portal

#

like when the door lock is opening

light crow
dark nacelle
#

don't you have a trigger for it ?

light crow
#

or this?

dark nacelle
#

to open the door animation

light crow
dark nacelle
#

anyway you can use anything really

#

bool

light crow
dark nacelle
# light crow

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

light crow
#

ok

dark nacelle
# light crow

you need an empty one, right click the empty one and set as Default starting clip

#

then create transition from empty to opening clip

light crow
#

there i go

dark nacelle
#

open is empty?

#

right click on it and create transition from that to the animation you want

dark nacelle
#

na

#

its backwards

light crow
# dark nacelle na

door portal back no longer have the animation and now open have the animation

dark nacelle
#

ohh.

#

thats fine then

#

so just select the transition arrow

#

and make sure its correct condition

light crow
#

like this?

dark nacelle
#

exit time should be unchecked or it will automatically transition

#

i showed you the page how to add transition condition

light crow
#

ok, i unchecked the has exit time

dark nacelle
#

you have to add trigger or whatever, as condition for transition

light crow
dark nacelle
#

alr

#

so do the reset. you have to call that from the script now

#

you should know where it goes

light crow
dark nacelle
#

the for loop and the Clear lists go in the else statement if you only want to reset if its not correct

dark nacelle
#

for loop is still wrong

light crow
dark nacelle
#

no

#

read again what I wrote

light crow
dark nacelle
#

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

light crow
dark nacelle
#

jesus..

dark nacelle
light crow
dark nacelle
#

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

light crow
#

how do i put lists only and the loop only in one else statement?

dark nacelle
#

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

light crow
# light crow

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

dark nacelle
#

Yes

#

ur supposed to but you didn't put all of it

#

you kept switching between both

light crow
dark nacelle
#

that took literally an hour and half

light crow
# dark nacelle no

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

dark nacelle
#

also its inverted

#

you're clearing the list before the loop..

#

this will break everything

#

it wont have any buttons to Reset on

light crow
dark nacelle
#

then re-read the rest of what I said it might make sense

light crow
dark nacelle
light crow
#

woah, it sure lasted much longer, like 6 hourse

dark nacelle
#

yes you have to take time to at least have more basics prepared, before doing such complex mechanics

light crow
#

and my computer here is responding slow

#

yeah ,so what's why i reply late a lot