disable script after x time passed

hey people, I this splashscreen script:

function next () {

 if(GUI.Button(Rect(Screen.width/2 - 90 , 600, 180, 40), "next"))
 
  {
    var script = GetComponent("MainMenuScript");
    script.enabled = true;
    var script2 = GetComponent("Splashscreen1");
    script2.enabled = false;
    }
}

If the next button is pressed, the menu loads and the splashscreen script is disabled.
but I also want, that this happens automatically after lets say 5 seconds, even if you don’t push the button.
how do I add such a timer to the if - function?
thanks for your help

I would move the script enabling/disabling part into its own function, something like EnableMainMenu(), then call that function in the GUI.Button conditional.

The you can call Invoke on EnableMainMenu outside of all your functions with a delay and it will fire the function after your delay passes.

Invoke("EnableMainMenu", 5.0);

function OnGUI(){
    Next();
}

function Next(){
    if(GUI.Button(Rect(Screen.width/2 - 90 , 600, 180, 40), "next"))
        EnableMainMenu();
}

function EnableMainMenu(){
    var script = GetComponent("MainMenuScript");
    script.enabled = true;
    var script2 = GetComponent("Splashscreen1");
    script2.enabled = false;
}

So in this script EnableMainMenu will fire if either the button is clicked, or five seconds passes.

Use Time.time …

check if Time.time == 5 seconds and do the same hope it shd work

thank you legend411, that works perfectly.