make multiple gameobjects flyoff in all direction after instantiating ?

i want to instantiate 10 cubes at a location and for that i am using for loop

private void Update()
{
    if (Input.GetKeyDown("z"))
    {
        for (int i = 0; i < 10; i++)
        {
            Instantiate(Cubee, transform.position, Quaternion.identity);
        }
    }
}

cubes has rigidbody so they fly off after instantiating because 2 rigidbodies cant stay in same location

now i want them to fly off in all direction, like a explosion
but they fly off only horizontally like shown in this (UNET | Spawning Objects Over Network - (Unity 5 Multiplayer) | C# - YouTube)

how do i make them fly off in all the direction ? like a particle system with spherical collider

Using the fact that rigidbodies repel one another to get an explosive effect does not give you a lot of control over the explosion. I suppose you could try randomizing the starting position of each cube by just a little in various directions and it may give you the effect you want, but if you want control over the explosion effect I recommend disabling collision between the cubes and then giving them each a random starting velocity.

I’d like to add to @unity_ek98vnTRplGj8Q 's answer and point you along to Random.onUnitSphere which is a good starting point for sampling directions you could use in your velocities for the different objects.

So in addition to instantiating the objects in the loop, you’d go through each of their respective rigidbodies and set its velocity to be something like

cubeRigidbody.velocity = 
                   Random.onUnitSphere * Random.Range(minExplosionVelocity, maxExplosionVelocity);

Here’s a short Youtube video that covers exactly how to explode a cube: How to Explode a Cube | Unity Tutorial - YouTube


exploding cube