- Home /
How can I instantiate one shot over another?
hi, I’m making a game in 2d, the player is cannon that shoots at enemies coming from above... there are 3 different gun sizes depending on how long you click on the cannon 0-2 s = shot small 2-4 = shot medium 4-6 shot big How can I instantiate one shot over another? thanks.
Clarify one shot over another? Do you want to shoot multiple bullets with one click? Do you want to switch bullets depending on how long you click it?
I want you to shoot one of these three shots example: click for 2 seconds on the cannon = Instantiate shot small click for 4 seconds on the cannon = Instantiate shot medium click for 6 seconds on the cannon = Instantiate shot big
Answer by GREYSETH · Aug 31, 2020 at 03:40 AM
@tyruss11 Make a float variable and call it clickTime (or somethin else) and in the update function do
If (Input.GetMouseButtonDown(0))
{
clickTime += Time.deltaTime;
}else if (Input.GetMouseButtonUp(0))
{
// clickTime is how long the player clicked in seconds
if (clickTime >= 2)
{
// Small shot
}
if (clickTime >= 4)
{
// Big shot
}
clickTime = 0;
}
If u don't know how to make the shooting then just search for shooting tuts on yt
Oh and the if (clickTime >= value) depends on your needs
Your answer
Follow this Question
Related Questions
Creating a GameObject variable without instantiating it? 1 Answer
Bullethole doesn't instantiate 1 Answer
I need my play button to load level 1 when the player touches the play button 2 Answers
How to handle A keyNoteFound Exception without Using A try catch Block? 1 Answer
The referenced script (Unknown) on this Behaviour is missing! 2 Answers