destroy problem please help thank you

i have some cubes in the scene which are destroyed as they are shot though when shot and destroyed the cube disapears instantiates 4 new ones all is fine with this though i would like the 4 new ones to be scaled down by say half the original size thats the first problem the next problem is that when i shoot the 4 smaller cubes i would like to destroy them completely and at the moment they instantiate 4 new onse again i know this is much please help me with this prolem its driving me insane

//Destroy cube
	if(hit.rigidbody.gameObject ==  hit.rigidbody.gameObject) 
	Destroy (hit.rigidbody.gameObject);
// Instantiate cube 

if(hit.rigidbody.gameObject == hit.rigidbody.gameObject){
		for (var i : int = 0;i < 4; i++)
		Instantiate (hit.rigidbody.gameObject,Random.insideUnitSphere * 8 + hit.rigidbody.gameObject.transform.position,  Random.rotation);
	}

Please don’t double-post.

You could have it instantiate a different kind of gameobject (a pre-defined smaller version) with a different script on it that has it get destroyed instead of spawning 4 new ones. You could also have your scripts on them have a special flag indicating if they should be destroyed or spawn new objects. If you want to use the same object type and just scale it down, use its localScale property (Unity - Scripting API: Transform.localScale).

It doesn’t sound like anything fancy is needed to achieve this, just script the logic in. Have you gone through the various tutorials and scripting resources available? If not, I strongly recommend that you do so.

tried useing the scale property and couldnt get it working with in my code

How did you use it?

Instantiate (hit.rigidbody.gameObject*******placed it in here***********,Random.insideUnitSphere * 8 + hit.rigidbody.gameObject.transform.position, Random.rotation);

Instantiate doesn’t let you scale objects as part of it’s function. See: Unity - Scripting API: Object.Instantiate

You need something more like this:

var subObject = Instantiate(hit.rigidbody.gameObject, Random.insideUnitSphere * 8 + hit.rigidbody.gameObject.transform.position, Random.rotation);
subObject.transform.localScale = new Vector3(0.5, 0.5, 0.5);

thank you for that it worked ill have to make all 4 of the cubes scale though the code worked on one for now cheers

i made it work thank you again i have to have this project finished by monday and have no idea about scripting you are a life saver just ahve to destroy the smaller ones now woth pout instantiating new ones

If it’s due by Monday, I guess you could do a quick “if” check on their local scale:

if (theTargetGameObject.transform.localScale.x < 1)
{
//destroy
}
else
{
//spawn smaller objects
}

ill give this a go tonigh and get back to you

thank you again

Just been messing with that code you gave and all I can say is thank you so much as it worked a treat, would you mind if I contact you through the private messages section of the forum for more help over the next few days would appreciate it a lot,

Thank you again