Hey there!
I am working on a little shooter game for college and i wanted to create a piece of glass that breaks on collision.
To do that i built an original piece of glass and the same one splattered in many broken pieces with Maya, imported them and put them into prefabs to add some glass material.
I placed one of the original glass pieces in my game and added following code:
public class Destruction : MonoBehaviour {
public GameObject destructionPiece;
void OnCollisionEnter(Collision collision) {
Instantiate (destructionPiece, this.transform.position, this.transform.rotation);
Destroy(gameObject);
}
}
If the Object collides with something it shall be destroyed and instead of it there should be the object with the many glass pieces.
So far so good, everything works, BUT:
The broken glass object appears at another location. I cannot give the two type of prefabs the same parameters. If i give the original one the paramters of the broken one, the first one has the size of a cube.
How could i give the 2nd object the correct location parameters inside of the code?
Thanks for your help!