respawn prefab at empty game object after the user has clicked the previous one

Hi All I was trying out my simple scoring script.

var buck : int = 1;
function OnMouseOver () {
if (Input.GetMouseButtonDown(0))
{
Destroy (gameObject);
ScoreBoard.SCORE = ScoreBoard.SCORE + buck;
}
}

How would I use this script on a prefab and make the prefab spawn at the point of an empty gameobject
And when clicked the prefab will destroy(above) but then after a certain amount of time the prefab will respawn.

Simply put, you need a reference to the spawn point in your script, so:

  • add a transform variable in your script.
  • drag the spawn point object in the scene into the transform variable
  • when you call ‘instantiate’ to spawn the new object, use the transform variable you allocated for the position parameter.

Thanks for your help but it doesn’t work because this is what I use on my empty game object to spawn the prefab(coin)

var Theprefab : GameObject;

function Start () {
yield WaitForSeconds(3);
var Instance : GameObject = Instantiate(Theprefab, transform.position, transform.rotation);
if (Input.GetMouseButtonDown(0))
{
Destroy (gameObject.Find(“coin”));

}

}}

The script I posted earlier is attached to the prefab I am spawning. I can spawn the coin when the level loads and click on it and it adds the points then destroys itself. How do I make it that after another 3 seconds the coin will spawn again at the same empty game object? Sorry for not having my code formatted but I cannot format it because I am using my blackberry phone and cannot select the text I want to format!

Add something like this to the end:

var spawnpoint:Vector3 = new Vector3(SOMETHING, SOMETHING, SOMETHING)
yield WaitForSeconds(HOWLONG)
Instantiate(NAME, spawnpoint, Quaternion.Identity);

The SOMETHING variables would be the X/Y/Z-positions of wherever you want to spawn the object again, HOWLONG would be the time (in seconds), and NAME is the name of the object you want to spawn.

Thanks@Umbra but here comes the problem that I forgot to tell you guys :confused: !!

My spawnpoint is connected to a building that is instantiated when I click on a gui button and then I can place it on my grid. So will that script work because it means that then my spawnpoint can be anywhere on the grid when the game is running . The reason I am struggling with this is because to use

Yield WaitForSeconds

The function has to be Function Start () and if I want to respawn the object I will have to use Function Update ()

Do you understand what I’m saying ??
What can I use besides Yield WaitForSeconds ?

What can I use instead of Yield WaitForSeconds() ?