I’m looking to code something similar to one part of the Ghostbuster’s game for the NES.
You drive a car around, and then a random building blinks red to indicate that you need to go there. When your car touches the blinking building, you go to the next scene / level. Touching any other building with your car does nothing.
I think I know how to code all of the controls, and how to make the building take you to the next scene when you touch it.
What I’m having trouble with is how to code it so that a random building is selected each time, and how to designate it as the building that will take you to the next scene.
Do I need to assign each building on the map a value, put it into an array, and then pick one at random somehow? Or is there something easier? And then how would you plug that randomized value in so that the building blinks red and transfers to a new scene when you touch it?
Any ideas?
You’ll pretty much have to assign it a value somehow. You can put it into a list, a 2d array, or a 1d array, doesn’t really matter, but since all the RNGs will provide you with is a number, you’ll eventually need to convert that number to the building.
As to blinking red, you just change the color attribute of the sprite renderer based on a clock value, alternating between red and white.
So what you’ll probably want overall is have a master controller object that has links to all the other building object. You could do this manually, or make it the parent of all the buildings and then just use the unity getchild functions, your choice. Either way, whatever structure you put that into will be indexed so you can use that index as your number that you check against your rng result. When needed, you can either have the master controller handle the blinking, or have a script on the building that flips it into blink mode and only turn on the one building.
1 Like