delayed function problem

I have 2 scripts attached to 2 different objects, when the first object becomes visible the second script whit my GUI is enabled, when the first object disappears, I want to close my GUI. The problem is that when the GUI is closed I can’t see the animations of the buttons in it because there’s no time to show them. This is my code, maybe it explains my problem better:

first script:

var otherScript : guifinal;

if (renderer.isVisible) {

	otherScript.enabled = true;

	}
else {
	DisableRendererWithDelay();
	}
}

function DisableRendererWithDelay() {
	yield WaitForSeconds(2);
	otherScript.enabled = false;
}

second script:

    function OnEnable(){
	
	iTween.ValueTo(gameObject,iTween.Hash("from",CurrentButtonSize(),"to",buttonVertSize,"easetype",iTween.EaseType.easeOutBack,"onupdate","ScaleButton","time",.5,"delay",.3));
	iTween.ValueTo(gameObject,iTween.Hash("from",VertButtonSize(),"to",buttonOrizSize,"easetype",iTween.EaseType.easeOutBack,"onupdate","ScaleButton","time",.5,"delay",1));

}	

function OnDisable(){
	
	iTween.ValueTo(gameObject,iTween.Hash("from",CurrentButtonSize(),"to",buttonNormalSize,"easetype",iTween.EaseType.easeOutBack,"onupdate","ScaleButton","time",.5,"delay",.2));

}

There is a way to send instantly the trigger of “otherScript.enabled = true” but execute it after 2 seconds?

You could try something like this …
In your second script:
Add a boolean variable, something like ‘disabling : boolean = false’
Then rename your OnDisable() function to Disable() and add disabling = false

function Disable(){
    iTween.ValueTo(gameObject,iTween.Hash("from",CurrentButtonSize(),"to",buttonNormalSize,"easetype",iTween.EaseType.easeOutBack,"onupdate","ScaleButton","time",.5,"delay",.2));
    disabling = false;    
}

Add an if statement in the update function of your second script

if(disabling) {  
    disable();  
}

In your first script:
just before you do your yield WaitForSeconds(2); add the line
otherScript.disabling = true;

Hope this makes sense :slight_smile: