Instatiating inside range between 2 spheres

Ok so I am feeling kind of stupid right now because this is a maths thing and I should be able to think it through but it is causing me problems even after searching for a solution.

Basically I have an enemy randomly spawning in a sphere around the player, but they occasionally spawn too close.

How would I get the enemy to spawn randomly inside a sphere but also have a minimum distance from the player?

Thanks

function GetRandomPosition( var minDist : float, var maxDist : float ) : Vector3 {
  var out : Vector3;
  while ( out == Vector3.zero ) out = Random.InsideUnitSphere();
  out = out.normalized * Random.Range(minDist, maxDist);
  return out;
}
...

enemyPosition = playerPosition + GetRandomPosition( 10, 20 );

How’s that?

Wow Unity Forums work fast.

Ralised after posting I forgot to say I was using javascript but there’s a post already haha.

But anyway, it returned this error:

BCE0077: It is not possible to invoke an expression of type ‘UnityEngine.Vector3’.

I can’t see what’s causing it, but then again that’s probably why I am running into the problem at all haha

EDIT: Wait, think I got it.

EDIT: Yep! Was no brackets encasing the while loop and insideUnitSphere didn’t need any brackets.

Seems to working perfectly, thanks a lot!