How can I switch prefab by the Alpha(number) and fire it by clicking left mouse

#pragma strict
var noSpell : GameObject ;
var iceBallPrefab : GameObject;
var fireBallPrefab: GameObject;
var shootSpeed: float;
private var spell: GameObject;
static var buttonDown : boolean = true;
//dadvar time : int = 2;

function Start () {
spell = fireBallPrefab;
}

function Update () {

if (Input.GetKeyDown(KeyCode.Alpha1)){

Spell_ice(iceBallPrefab);
}

if( Input.GetKeyDown( KeyCode.Alpha2 ) ) {

Spell_fire(fireBallPrefab);
}
}

/* if( Input.GetKeyUp(KeyCode.Alpha2) ) {

if( Input.GetButtonDown(“Fire1”) ) {
Destroy(iceBallPrefab);
spell = fireBallPrefab;
var fire_ball : GameObject = Instantiate( fireBallPrefab, transform.position, transform.rotation );
fire_ball.rigidbody.AddForce(transform.forward * shootSpeed);
}
}
}

if(Input.GetButtonDown(“Fire1”)) {

Destroy(fireBallPrefab);
spell = iceBallPrefab;
var ice_ball : GameObject = Instantiate( iceBallPrefab, transform.position, transform.rotation );
ice_ball.rigidbody.AddForce(transform.forward * shootSpeed);

}
*/

function Spell_ice(iceBallPrefab) {
if( Input.GetButtonDown(“Fire1”) ) {
Destroy(noSpell);
var ice_ball : GameObject = Instantiate( iceBallPrefab, transform.position, transform.rotation ) ;
ice_ball.rigidbody.AddForce( transform.forward * shootSpeed ) ;
}
}

function Spell_fire (fireBallPrefab) {
if( Input.GetButtonDown(“Fire1”)) {
Destroy(noSpell);
var fire_ball : GameObject = Instantiate (fireBallPrefab, transform.position, transform.rotation ) ;
fire_ball.rigidbody.AddForce( transform.forward * shootSpeed ) ;
}
}

Here’s my code. Basically, what I intend to do is if I hit number 1, the spell will be ice_ball, if I hit number 2 on the keyboard, it switches to fire_ball spell. Right now, it switches, but I can’t fire it at my will. I have to hit the number key and the left mouse button at the same time to fire the spell. Please help!

Don’t post code without code tags please.

–Eric

you’ve got the following flow

update
      if keypress: call "spell fire"

         "spell fire"
               if mouse click: actually fire the spell
         end "spell fire"
 
end update

you want

update
      if keypressed: change spell
      if mouse click: actually fire the spell
end update

I’m sorry, it’s my very first post in this forum. It won’t happen again

It works, thank you.