How to change a public variable from another script?

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:

  1. 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;}.
  2. 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

I’m not entirely sure what you’re asking, but purely in terms of accessing a public variable from another script I’d recommend you write something like this

public GameControl insertName;

declare that with your other variables

when you want to change it use insertName.scrollSpeed in place of the variable