In my game there is a bird flying and on touch it throws different artifacts projectile downwards. And these artifacts should hit the containers moving right to left on the screen. Now if user keeps on tapping rapidly it make a line of artifacts and it didn't miss a single container. So what I want to do is to restrict user to throw 3 artifacts at a time and when one of them got destroyed it'll make room for one more. Here is how I'm doing it:
In my player.cs
I'm using a static
int
named inventory
and then in Update()
method I've the code where it increment the inventory.
if (Input.GetTouch(i).phase == TouchPhase.Began){
OnShoot ();
inventory++;
Debug.Log ("Inventory: " + inventory);
}
and in OnShoot()
I'm checking if (inventory < 4)
then Instantiate
otherwise if (inventory > 4)
set inventory = 0;
.
Now in the artifacts.cs
if
it hit the container and get destroyed
or got destroyed
going out of the bound missing the container it should Player.inventory--;
This code works fine but if the user speed of tapping is more then it again started throwing like in a line form as described above.
inventory = 0
inOnShoot
is a mistake? It's kinda hard to answer without the relevant bits of code though. \$\endgroup\$