JavaScript: Accessing instantiated objects outside the instantiating function

Hi guys!
I’m pretty new to Unity and scripting and I could get rid of most of the problems that occurred so far. But now I’m having a little prob with a function which I want to destroy an initiated game object.
My aim is to spawn a fireball in each hand of the caster (parented the hands temporarily to make them follow the hands) with this function:


function SpawnFireballInBothHands(){
var FireballLH : GameObject;
var FireballRH : GameObject;
FireballLH = Instantiate(FireballPrefab, magicSpawnPointLHand.position, magicSpawnPointLHand.rotation);
FireballLH.transform.parent=magicSpawnPointLHand;
FireballRH = Instantiate(FireballPrefab, magicSpawnPointRHand.position, magicSpawnPointRHand.rotation);
FireballRH.transform.parent=magicSpawnPointRHand;
Debug.Log("> Fireballs initiated");
}

Works fine so far, but I can’t access the fireballs through a different function. I guess it’s because the variables aren’t declared as private ones, but when typing ‘private var FireballLH…’ instead of ‘var …’, Unity tells me that it’s
‘expecting }, found private’.

Any suggestions? Declaring them as ‘private’ outside a function would result in the player being able replace the fireballs each time the spell is casted, even if the fireballs are still flying, wouldn’t it?

Thx in advance,
nbase

As you answered yourself, attach a script to the fireballs themselves. This is what OOP is for - make the fireballs self-aware, then just fire-and-forget.