- Home /
Question by
thommoboy · Apr 25, 2012 at 06:59 AM ·
androidjavascript
Same commands firing multiple times android
hey whenever i touch my screen where i have defined it shoots but takes off a random number sometimes 1 sometimes 4 or 5 here is my code:
here is where i call the event:
if( ShootTouchPad.IsFingerDown())
{
Attack();
BulletsLeft -= 1;
if(BulletsLeft < 0)
{
BulletsLeft = 0;
}
if(BulletsLeft == 0)
{
Reload();
}
}
and here is the command called:
function Attack()
{
Debug.Log("Shot");
var Hit : RaycastHit;
var DirectionRay = transform.TransformDirection(Vector3.forward);
Debug.DrawRay(transform.position, DirectionRay * Range, Color.blue);
if(Physics.Raycast(transform.position, DirectionRay, Hit, Range))
{
if(Hit.rigidbody)
{
Hit.rigidbody.AddForceAtPosition(DirectionRay * Force, Hit.point);
}
}
Comment
Best Answer
Answer by programmrzinc · Apr 25, 2012 at 12:50 PM
I would do It Like This:
var BulletsLeft : int =5;
var Ready2Shoot : System.Boolean = true;
function Update() {
if( ShootTouchPad.IsFingerDown()){
if(BulletsLeft < 0){
Attack();
if(BulletsLeft == 0){
Ready2Shoot = false;
Reload();
}
Function Reload(){
BulletsLeft = 5;
//Reload ANim stuff
//When you are done...
Ready2Shoot = true;
}
function Attack(){
`//Attack stuff`
BulletsLeft = BulletsLeft - 1; }
would this also fix the $$anonymous$$using more than one bullet per shot?
Your answer
![](https://koobas.hobune.stream/wayback/20220613070730im_/https://answers.unity.com/themes/thub/images/avi.jpg)