Help with item respawn after picking up!

Hi guys,

So ive managed to make my script work this far, but now im stuck at this last part.

Basically what i want to do is make the item respawn after you pick it up.
As you can tell by my commented out code ive already tried to get it to work myself but im all out of ideas on how to make this work in the most simple way.

Heres my script:

public var timer : float = 3;
private var Items : int;
public var SpawnPosition : GameObject;
public var canpickup : boolean = true;

public var Item1 : GameObject;
public var Item2 : GameObject;
public var Item3 : GameObject;
public var Item4 : GameObject;
public var Item5 : GameObject;

function Start()
{
    timer = 3;
    canpickup = false;
    Items = Random.Range(1,5);
}

function Update ()
{
    if(canpickup == false)
    {
        timer = timer - Time.deltaTime;
        {
            if (timer <= 0)
            {
                if (timer == 0);           
            
                if (Items == 1)
                    {
                    Instantiate(Item1, SpawnPosition.transform.position, SpawnPosition.transform.rotation);
                    canpickup = true;
                    timer = 3f;
                    }
                    else
                    {
                    //(Item1 == null);
                    canpickup = true;
}

                    if (Items == 2)
                    {
                    Instantiate(Item2, SpawnPosition.transform.position, SpawnPosition.transform.rotation);
                    canpickup = true;
                    timer = 3f;
                    }
                    else
                    {
                    //(Item2 == null);
                        canpickup = true;
}

                    if (Items == 3)
                    {
                    Instantiate(Item3, SpawnPosition.transform.position, SpawnPosition.transform.rotation);
                    canpickup = true;     
                    timer = 3f;
                    }
                    else
                    {
                    //(Item3 == null);             
                        canpickup = true;
}          
                       
                    if (Items == 4)
                    {
                    Instantiate(Item3, SpawnPosition.transform.position, SpawnPosition.transform.rotation);
                    canpickup = true;
                    timer = 3f;
                    }
                    else
                    {
                    //(Item4 == null);
                        canpickup = true;
}
                               
                    if (Items == 5)
                    {
                    Instantiate(Item5, SpawnPosition.transform.position, SpawnPosition.transform.rotation);
                    canpickup = true;
                    timer = 3f;
                    }
                    else
                    {
                    //(Item5 == null);
                        canpickup = true;
                    }
            }
        }                 
    }
}

Instead doing a lot of if statements just store all Your prefabs in a List.

List<GameObject> Items = new List<GameObject>();

Then all You have to do to spawn it is:

Instantiate(Items[itemIndex], SpawnPosition.transform.position, SpawnPosition.transform.rotation);

Thanks for the response but could you edit that to Javascript, please?
My initial topic question still stands btw…

What I would do is create a list/array of items. You could either place the objects in the scene or instantiate them but when the player walks over an item, instead of destroying that item and respawning, what you could do instead is hide the object and disable the collider and then re-activate the item after a certain amount of time has elapsed. So what you could do is create a timer function and pass it a float/int paramter and when the time has been reached then toggle the visibility of the object.

Hope this helps.

-Joshmond