Hi all. Looking for some ideas on how to implement a puzzle. I have a Roll a Ball level and I want to have it so the ball has to roll over buttons in a certain order to open the gate, starting with 3 buttons at the first puzzle.
The logic for getting the switches to work correctly for detecting the correct sequence is simple enough, this issue I am having is resetting back to the starting state once the wrong sequence is made.
The main problem, I believe, is I am trying to avoid a huge script on my rolling ball, so I have a script on each of the buttons and the scripts all reference each other. The sequence of operation is basically when the ball rolls over a button the OnTriggerEnter evaluates if the order is correct, if so changes button from red to green. On the next button same thing until either the gates open or a wrong button pressed at which point all the buttons go back to red. This is where the problems begin.
To determine if the order is correct the button script reads the state of the other two buttons via a serialized field variable. However I don’t know how (in my limited knowledge) to set a variable on another script, so the only way I have found to reset the other two buttons once the wrong one is activated is by having the Update methods scan the other buttons and resetting when needed. But once they reset they will not leave reset mode because the constant updating. I even tried using and additional variable that got me one step further down the line, but it still left me in reset mode.
I am about 95% sure I can code this if I place all the code on my rolling ball, since I wouldn’t require the Update function to look for the reset.
I’m not looking for anyone to code it for me, just more like point me in the right direction, or flat out tell me I am an idiot to do it this way and just use the ball script.
Ok, so I’m feeling like an idiot and at the same time feeling a bit smart because I figured it out.
I assumed that when I call another script it was only one way, as in I could get a variable, but not write back to that script. I decided to stop being fancy and having the first script use Update to scan for the changes I made in the second script and just change the variable directly and it worked flawlessly.