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 {

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

second script:

    function OnEnable(){


function OnDisable(){


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(){
    disabling = false;    

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

if(disabling) {  

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

Hope this makes sense :slight_smile: