Trying to understand GetActive (true)

I’m still pretty new to Unity. I’m actually just trying to make some type of item (like a coin) respawn after a certain amount of time after the player grabs it.

I have a Spawn Script attached to an empty game object to spawn my coin at start. I also have a script attached to a player that makes the object inactive when touched (trigger). That seems to work fine.

I’m still stuck on how to make my prefab active again after a certain period of time.

This is my script attached to my Spawn Game object but the Update part is a test. I would think by having the SetActive always true in the Update function that the coin would never disappear but it does dissapear when the player touches it still. Why is that? (just trying to understand the logic here)

If anyone has any input on how to delay randomly before the coin gets set active again (and how to set it active) I’d be grateful.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SpawnPoint : MonoBehaviour {

	public GameObject spawnAsset;

	// Use this for initialization
	void Start () {

		Instantiate(spawnAsset, transform.position, transform.rotation);
		
	}

	void Update ()
	{

		spawnAsset.gameObject.SetActive (true);
		
	}



	
}

What is happening with SetActive() is that you are referencing the prefab to spawn not the actual one that you spawn in the game.

Instead you want to create a reference for the spawned one.

Like this:

private GameObject spawnedAsset;

void Start()
{
  spawnedAsset = Instantiate(spawnAsset, transform.position, transform.rotation) as GameObject;
}

After you have assigned the reference you can use SetActive() as you were before.

spawnedActive.SetActive(true);

In regards to delaying until the coin becomes active, I would suggest using a Coroutine or similar and having it wait for a specified amount of time before it turns back on.