[SOLVED] Random.range for a prefab ?

Hi guys
this is my script.

        {
// souls Random.range(1,4) !!!
            Instantiate(souls,transform.position,transform.rotation);
// souls = prefab object with collider and rigidbody.
        }

when i kill my enemy, his soul drop down as orbit or ball, good thing. This soul should not effect from the physic around it. like if something hit it, it moves. how to do this ?

What components do the souls have? Sounds like you have given them a collider and a rigidbody. Not sure if the rigidbody is needed though as that will make it use physics. so if possible remove that. For the collider you could set it to a trigger so that other objects pass through it.

I know this. if trigger = true. it will not touch the ground. and without gravity will be on air flying.
Look at this

One more thing, How to make a random of souls drop out ? between 1-4

So, they should react to physics (in this case gravity) but not be able to be touched by other objects. In that case use collision layers

Pseudo code:

var amount = Random.Range(1, 4);
int count = 0;
while(count < amount);
{
    Instantiate(blah blah);
    count++;
}

As a warning btw, Random.Range(int, int) is different from Random.Range(float, float). For the int version the max (second param) is exclusive where in the float version it is inclusive. Using above sample:
Random.Range(1, 4) → return 1-3
Random.Range(1f, 4f) → return 1-4

1 Like

Thank you so much timelog.
[Solved]