When you instantiate something, you clone it, put it in the position you want, and the rotation you want. A very simple command. Done like this:
function Update(){
Instantiate(transform, transform.position, transform.rotation);
}
So basically what this script does is clones what ever the script is attached to at the position of the object, and its rotation. Not really the best thing. Better yet it's in the Update function, which is being called every frame thats rendered, so thats allot of clones ha..
Using this to our advantage, we can use Instantiate to help us create an explosion effect =D
var explosion : Transform;
function OnCollisionEnter(){
Instantiate(explosion, transform.position, transform.rotation);
Destroy (gameObject);
}
Function on collision enter is called when one object has collided with another object, noting that they both have to have a mesh collider/rigid body attached to them. The instantiate statement clones the object that we assigned in the variable, which would be an explosion prefab. The Destroy (gameObject) deletes what ever the script is attached to.
Read more about Instantiating objects here
function Update(){
Instantiate(transform, transform.position, transform.rotation);
}
So basically what this script does is clones what ever the script is attached to at the position of the object, and its rotation. Not really the best thing. Better yet it's in the Update function, which is being called every frame thats rendered, so thats allot of clones ha..
Using this to our advantage, we can use Instantiate to help us create an explosion effect =D
var explosion : Transform;
function OnCollisionEnter(){
Instantiate(explosion, transform.position, transform.rotation);
Destroy (gameObject);
}
Function on collision enter is called when one object has collided with another object, noting that they both have to have a mesh collider/rigid body attached to them. The instantiate statement clones the object that we assigned in the variable, which would be an explosion prefab. The Destroy (gameObject) deletes what ever the script is attached to.
Read more about Instantiating objects here
Comments
Post a Comment