- Home /
Changing background color every time I score
I am currently working on my 2D android game. I am trying to make my background change every 5 seconds / or even better every time I score 5 points. I don´t want to change the colors randomly infact, I want to change the colors from (white to yellow to orange to red.. etc) I had a pretty good idea on how to do that.
public Rigidbody rbWhite;
public Rigidbody rbYellow;
rbWhite = GetComponent<Rigidbody>();
rbYellow = GetComponent<Rigidbody>();
if(score > 10) { rbWhite.gameObject.SetActive(false); rbYellow.gameObject.SetActive(true); }
What I tried to do is create a parent class "BGColors" and set it to active. It´s childs would be the other BG Colors. I would add Rigidbodies to them(note: I know there is a better way to do that, I just don´t know how). Then I would create a couple if statements if (score>20) turn white off and turn yellow on, if (score > 40) set yellow to off and set orange to on and so on.
There is no compiler error.
But for some reason it doesn´t work even if I change the if statement to (true). I would really appreciate if someone would tell me why this doesn´t work and change it so it would work and be reasonbale to me.
In this code:
rbWhite = GetComponent<Rigidybody>();
rbYellow = GetComponent<Rigidybody>();
Both rbWhite and rbYellow are the same, GetComponent return the component for the actual object to get the rigidibody of the children use GetComponentInChildren to get one rigidbody amoung th children, or GetComponentsInChildren to get a array of rigidbody of all children or use a reference to a object to get the component rbWhiteObject.GetComponent.
Your answer
Follow this Question
Related Questions
Carry over texts from one scene to another? 1 Answer
Score system 1 Answer
Displaying the score after a reset. 2 Answers
2D - draw sprite only on one background color 0 Answers
Why does my Android phone show colors incorrectly? 3 Answers