hello there.
I’m doing instantiate and manage to do it, but having problem when the gameObject instantiate. The gameObject will overlap each other even I put a min and max range for the gameObject.
How do I tell the gameObject not to overlap each other?
Another question is about the gameObject that being instantiate. As for now I have 3 type of gameObject that I want to instantiate, example : Button1, Button3, Button3. How do I instantiate all the 3 gameObject. If I used Random.Range it will pick either 3 of the gameObject.
Here’s what I’ve done so far:
#pragma downcast
#pragma strict
#pragma implicit
public var button : Transform [];
public var rangeY : float;
public var nRangeY : float;
public var rangeX : float;
public var nRangeX : float;
public var i : int;
public var spawnAmount : int;
public var maxAmount : int;
public var minTime : float;
public var maxTime : float;
public var canSpawn : boolean;
function Awake ()
{
canSpawn = true;
if (spawnAmount > maxAmount)
{
spawnAmount = maxAmount;
}
for (i = 0; i < spawnAmount; i++)
{
beforeSpawn ();
}
}
function beforeSpawn ()
{
if (canSpawn)
{
yield WaitForSeconds (Random.Range (minTime, maxTime));
var position : Vector2 = Vector2 (Random.Range (nRangeX, rangeX), Random.Range (nRangeY, rangeY));
Instantiate (button [(Random.Range (0, 2))], position, Quaternion.identity);
canSpawn = false;
}
}