I am making a game. In my game, I set a public variable of scrollSpeed in the GameControl.cs, which is to control the scrolling speed of several objects.
I want to set: if two certain gameobjects collide to each other, then the scrollspeed will change.
I tried two ways:
- In the script of the collided gameobject, I imported the public variable by GameControl.instance.scrollspeed, then I changed it directly by: if (collision) then {GameControl.instance.scrollspeed=10f;}.
- I wrote a public function in GameControl.cs, like: public void changeSpeed() {scrollSpeed=10f;}, then in the gameobject script, I invoked this public function, like: if (collision) {GameControl.instance.changeSpeed()};
Both ways don’t work. Unity gave me no error, running smoothly but the speed does not change at all.
I don’t know why I can’t not change it. I feel there is some tricky when we change the physics parameters in the middle of the game. But i am not sure.
If anyone can give me some advices, that would be sooooo nice!
Thanks