- Home /
Using c# to Set a Button's Color onto a GameObject in Another Scene?
I'm using sprites as GameObjects in my Game scene. They are desaturated, and have a starting color (in the sprite renderer) of White. On my Start scene, I have a store canvas with a scroll rect containing a ton of buttons that use the images of the sprites in the game. I have these buttons colored (in the sprite renderer) many different colors. Can I write a script in c# to put on the store buttons, so that if you click one, it sets the specific GameObject's color to the button's color? Also, I'm trying to make these buttons remain disabled until you reach certain high scores (which I already have saved in PlayerPrefs). So for example the first button is set to yellow, and requires a high score of 5 to unlock and equip it. Thanks, guys!
Answer by Stemo688 · May 16, 2018 at 05:06 PM
You can't access other GameObjects in an another scene, but you can save what you did before in a static class or in the Player Prefs. Example: You touch a button, in Player Prefs you save an int like "ButtonTouched" = 1, then in the other scene change the color of the button in Start() if "ButtonTouched" is 1 and then set it back to 0.