Hey there. I have a problem with a section of code in my weapon script.
Simply put, it won’t call fire multiple times :
void Update() {
//Updates ammo Meter
if(ammoBox == 0 && clipBullets == 0)
{
lcdMeter.text = "--";
}
else
lcdMeter.text = clipBullets.ToString();
int count = Input.touchCount;
for(int i = 0;i < count; i++)
{
Touch touch = Input.GetTouch(i);
bool shouldLatchFinger = false;
Vector2 firstTouch = Vector2.zero;
if(touch.phase == TouchPhase.Began)
{
firstTouch = new Vector2(touch.position.x, -touch.position.y + Screen.height);
print("i");
}
else if(touch.phase == TouchPhase.Canceled || touch.phase == TouchPhase.Ended)
{
firstTouch = Vector2.zero;
print(firstTouch);
}
if(fireButtonRect.Contains(firstTouch))
{
print("Fire!");
// Keep firing until we used up the fire time
if( prevFire + fireRate <= Time.time)
{
FireWeapon();
prevFire = Time.time;
}
}
}
}
The problem is that it doesn’t trigger the “Fire!” continuously. it fire it once…which I really don’t get…