Hi All!

I’m trying to change a variable in a script during a OnTriggerEnter function in antoher script.

var AddTime : float = 15;
var obj: GameObject;
var script: Component; 

    function Start(){
    obj = GameObject.Find("GUIcounter");
    }

    function OnTriggerEnter(){

    var script: GUICountDownTimer = obj.GetComponent(GUICountDownTimer);
     script.restSeconds = script.restSeconds + 10; 
    print(script.restSeconds);
    }

It’s mainly about the line

script.restSeconds = script.restSeconds + 10;

This does seem to change the variable, but in This script, I need it changed in the other script, GUICountDownTimer. How do I do this?

Thanks in advance!

Aha! I knew it! You’re setting restSeconds each OnGUI, so any alteration made in the other script will be overwritten.

You could add the extra time to countDownSeconds instead. - it seems to be the easiest way to do it without big changes in your code.