# Help with powerup code

So I am using a quick powerup system which requires different inputs i want the ‘e’ button to activate my powerup and then when i click the mouse button i fire 3 balls in a cone. here is my code can anyone help me?

var projectile : Rigidbody;

var angledifference:float = 20;

function Update () {

if(Input.GetKeyDown(KeyCode.E))

{
if (Powerup.currentpowerup == 1)
{
MultiBall();
}
}
}

function MultiBall ()

{ Debug.Log(“Running MultiBall”);

if(Input.GetMouseButtonDown(0))
{
Debug.Log(“Clicking Mouse”);
var ballRot= transform.rotation;
ballRot.x += angledifference;
var clone : Rigidbody;
clone = Instantiate(projectile, transform.position, ballRot);

// Give the cloned object an initial velocity along the current
// object’s Z axis
clone.velocity = transform.TransformDirection (Vector3.forward * 200);

var ballRot2 = transform.rotation;
ballRot2.x -= angledifference;
var clone2 : Rigidbody;
clone2 = Instantiate(projectile, transform.position,ballRot2);

// Give the cloned object an initial velocity along the current
// object’s Z axis
clone2.velocity = transform.TransformDirection (Vector3.forward * 200);
}
}

for some reason it gets to the Runnign Multiball debug line but no further

I try to explain the problem of your code:

You check the key press ´E´ in your Update() function.
If you press the ´E´ key, you check if your Powerup.currentpowerup is set to 1. (Your question says: i want the ‘e’ button to activate my powerup. But you do not activate it in this code. This happens somewhere else, or it is activated already).

If Powerup.currentpowerup is set to 1 the function MultiBall() is called.
You get the Debug.log ´Running Multiball´.
Then you check if you press the mouse button. If not, the MultiBall function will do nothing. Here is your problem.
The MultiBall function do not wait for your mouse klick. It returns if you not klick the mouse.
You have to klick the mouse and the ´E´ key to the same time, then it works.

You have to check the mouse in the Update(). Try something like this:

``````function Update () {

if (Input.GetKeyDown(KeyCode.E)) {
Powerup.currentpowerup = 1;               // switch on the powerUp by ´E´ key press
}

if ( Powerup.currentpowerup == 1  Input.GetMouseButtonDown(0) ) {     // check if powerUp is 1 and the mouse button is pressed
MultiBall();
}

}
``````

(not tested, but i think it works)