Hello! Total Unity/coding newbie here. I recently completed the 2D Space Shooter Tutorial and am trying to make it so the background and star field move faster when the player has won the game by getting a score of over 100. How would I go about doing that? I would assume under my background scroller script but the game controller script is what holds all the code for score. Any help would be greatly appreciated!
It sounds like you’ve done some great investigating in the codebase and you almost have the solution.
At least you have the input (score) and the output (scrolling) identified in code. I REALLY respect that! Bravo!
I think all you want is to make a new script that monitors the score value from that other script, then adjusts the scroll speed.
Basically in your new script you would need (via inspector reference fields):
- a reference to the game manager script
- a reference to the scrolling script
(This is the normal way of telling scriptA about ScriptB in Unity)
In the update of this monitor script it would:
- use the game manager reference to get the score
- calculate new scroll speed based on the score
- use the scroll controller to set the new scroll speed
Also, you have to make sure those variables are marked public to read them from the monitor script.
1 Like