prefab not spawning on object
Hey all, I'm making a simple game where a building blows up and I have a solid cube used as the building, then when Space is pressed the cube object is destroyed and a group of smaller cubes replaces it, these cubs then tumble to the ground, acting as fragments of the original larger cube.
The problem I'm having is my code doesn't spawn the group of smaller cubes (which are all assigned to an empty object) at the solid cube, they spawn off in the distance for some reason.
Here is my code:
var remains: GameObject;
function Update()
{
if(Input.GetKey(KeyCode.Space))
{
Instantiate(remains, transform.position, transform.rotation);
Destroy(gameObject);
}
}
Can anyone help me out please? Thanks in advance.
In your code is 'remains' linked to something as it is just an empty game object as that is all you have made it at the moment.
I have linked it to an empty object that contains the fragments within it
Your answer
![](https://koobas.hobune.stream/wayback/20220612064756im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can i Delete original Keep Clone 1 Answer
Destroying a spawn object when it exit the main camera view not working 0 Answers
Spawning only 1 gameObject 3 Answers
Create only one Instantiated Object 1 Answer
Bullet Destroy 1 Answer