Hi all. I’m new to unity. Been using it for all of 3 days. Im writing a ‘game’ and it seems to be going quite well.
The game involves collecting ‘objects’.
What I need to know is the best way of going about destroying the first object when touched and spawning a new one.
The script that spawns the first object works fine, and when you touch it, it dissappears.
Just wondering about getting the next object to spawn.
Here are the scripts that im using:
SpawnCollectable.js
#pragma strict
var prefab : GameObject;
function Start () {
var position: Vector3 = Vector3(Random.Range(-10.0, 10.0), 2, Random.Range(-10.0, 10.0));
var object = Instantiate(prefab, position, Quaternion.identity);
object.transform.parent = transform;
print (Random.Range (0,10));
}
TouchCollectable
function OnCollisionEnter(col: Collision){
//Debug.Log(GameObject);
if (col.gameObject.tag == "PlayerMarble"){
Destroy(this.gameObject);
//Spawn a new one here
}
}
The second script (TouchCollectable) is attached to the prefab.
Would I call the first script again from within this, or is a whole peice of code needed?
Thanks for the help.