The game is set inside of a nuclear power plant, and nuclear power plants need siren lights in case of emergency right?
My goal was to create something functionally identical to one of these siren lights. Surprisingly it was extremely easy. It took two lines of code.
Set a rotational speed, and make it rotate in the direction by (time x speed).
Fiddling with such a simple light had my lighting senses tingling. I though what else needs some lighting? The elevator perhaps?
Excellent! But perhaps they would be better off only activating when the elevator arrives? The elevator would need to know to activate it’s lights when it arrives. Because the elevator is already counting to when it arrives I could simply insert another method that would activate the lights.
I felt like the elevator could be improved on just a little bit more. If the game is supposed to be 4 minutes long and the goal of the game is to escape via the elevator, there should be an indication of how close the elevator is to the 5th underground floor.
6 lights. From left to right (-5, -4, -3, -2, -1, Ground). Next was to change these lights to show the elevator moving.
The elevator would need:
- An array of all of the lights. = GameObject lights;
- Which is the current light. = int current Light;
- Which light to change to.
- The time since the game has started. = float lightTimer = Time.time (in start).
- How often the lights should change. = float lightRefreshTimer;
How often the lights should change is determined by the length of the game. If there are six lights, and the game is 4 minutes long, the light should change every lightRefreshTimer amount of seconds.
lightRefreshTimer = (elevatorTime / (amount of lights in the lights array – 1)). Because there are six lights, but the first one is already active, the elevator only has to move down 5 levels, not six.
So if the (Time.time – lightTimer >= lightRefreshTimer)) Change the lights() and refresh the time duration.
The SwitchLights() method sets the current light off, Changes the value to the next light, and turns that one on. Each time that method is called it changes the current light to the next one. But what happens if all of the lights have been changed and the timer is still going? I’d need a way for the last light to be the last light. Above the if statement to that checks if the Time.time – lightTimer >= lightRefreshTimer is another if statement. It checks if the current light isn’t greater than or equal to the amount of lights in the light array. If it isn’t it executes the code underneath, otherwise it doesn’t.
Something that tripped me up was not having the levelLights.length – 1.
The currentLight variable starts at 0 and only ever reaches 5. So when it comes around again to the levelLights.length (which is 6) it would try to activate something that wasn’t there. Hence having the -1 to the levelLights.length to make that also = 5.
Until next time –