In one script (JS) I have this code:
static var newBall: GameObject;
static var ballPool = new List.<GameObject>();
function MakeBallPool ()
{
for (var n = 0; n < 200; n++)
{
var newBall: GameObject;
newBall = Instantiate(ballPrefab, transform.position, transform.rotation);
newBall.SetActive(false);
ballPool.Add(newBall);
}
}
Then on my other script I am trying (being the operative word) to get the balls from this “pool” into my using list. Here is the code:
var listBalls = new List.<GameObject>();
function drawBalls ()
{
var x: float;
var y: float;
if (existsBalls == false)
{
x = Random.value * 100 - 50;
y = Random.value * 100 - 50;
Manager.ballPool.Remove(Manager.newBall);
Manager.newBall.transform.parent = this.transform;
Manager.newBall.transform.localPosition = Vector3(x, y, 0);
Manager.newBall.SetActive(true);
listBalls.Add(Manager.newBall);
}
existsBalls = true;
}
}
Now first of all I realise I was a complete spanner and daft to be wondering why I kept getting the same ball due to the static. But the question is how do I get this to pass across properly? Any help would be really appreciated I have trawled through everywhere and know I am missing the obvious.