Timer calls it multiple times (loadingscreen) #help

Hello,
I am new with programming and making scripts (I am still trying to understand them)
So this is the case, I found some scripts on the web and tried to merge them together for my needs. In this case i wanted to make a loadingscreen.

*Problem : Something is calling it multiple times and because of that it looks like it’s shuffling a deck of cards. And after the 5 second restSeconds it doesn’t want to disable the GUI.

This is the script i am using.

private var startTime;
private var restSeconds : int;
private var roundedRestSeconds : int;

var countDownSeconds : int;

static var LoadingScreenOn = true;

//Texture
var Picture_1 : Texture2D;
var Picture_2 : Texture2D;
var Picture_3 : Texture2D;
var Picture_4 : Texture2D;
var Picture_5 : Texture2D;


function Start () 
{ 
	
//Called in when entering another scene.
startTime = Time.time;
var guiTime = Time.time - startTime;
restSeconds = countDownSeconds - (guiTime);

//As soon the timer hit 5, the LoadingScreen-GUI will be disabled.
    if (restSeconds == 5) {
    Loading_Screen.LoadingScreenOn = false;
	guiTexture.enabled = false;
    }
 
}

//required to let the randomize succeed.
function Update () 
{
	if (Loading_Screen.LoadingScreenOn == true)
	{
		RandomPic();
		guiTexture.enabled = true;
	}
}

//randomize a picture to be displayed
function RandomPic()
{
	var randPic = Random.Range(0, 5);
	var chosenPicture = randPic;
	
	switch (chosenPicture)
	{
		case 0:
			guiTexture.texture = Picture_1;
		break;
		case 1:
			guiTexture.texture = Picture_2;
		break;
		case 2:
			guiTexture.texture = Picture_3;
		break;
		case 3:
			guiTexture.texture = Picture_4;
		break;
		case 4:
			guiTexture.texture = Picture_5;
		break;		
	}
}

I have no idea why it is behaving like this. I hope you guys can help me out.

-Hexer

Start() is called only once when the script gets loaded and Update() is called one time for each frame (which is many times a second). So you are right in moving the RandomPic() to the Start() function.

The problem with the timer is the same, as Start() is only being called once, and you only check if the resSeconds equals to 5 there, which it will never be. You have to move the timer logic to the Update() to check for time each frame. You should also not check if the timer is equal to 5, because it uses decimal numbers and the likelihood of it ever being exactly 5 is very small. Rather check if the timer is more than 5. You can also use the Loading_Screen.LoadingScreenOn variable to check if the timer should run.

Something like this:

function Start () 
{ 
    if (Loading_Screen.LoadingScreenOn == true)
    {
       RandomPic();
       guiTexture.enabled = true;
    }

    startTime = Time.time;
}
 
function Update () 
{
    if(Loading_Screen.LoadingScreenOn == true){
       var guiTime = Time.time - startTime;
 
       if (guiTime > countDownSeconds) {
          Loading_Screen.LoadingScreenOn = false;
          guiTexture.enabled = false;
       }
    }
}

Edit: Also make sure to follow @robhuhn advice and read up on Monobehaviours.