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);
}
}