Hi, so I have a UI Button which when pressed activates a FireNow() function, which fires a bullet. Now I want to fire continuously, so I have added OnPointerDownHandler and OnPointerUpHandler to my code. But I am not able to access these functions in my FireNow function. This is the code. How do I access them in FireNow(). The Shoot() function performs the real shooting.
public void OnPointerDown(PointerEventData eventData)
{
ispressed = true;
}
public void OnPointerUp(PointerEventData eventData)
{
ispressed = false;
}
// Update is called once per frame
public void FireNow () {
if (isreloading)
return; //if reloading then don't go ahead
if(currentammo<=0) //if we have no ammo
{
StartCoroutine(Reload()); //reloading done here through coroutine
return; //don't go ahead in this function
}
if (Time.time >=nextTimeToFire && ispressed) //Input.GetButton("Fire1") and Time.time adds real time
{
Shoot(); //function to shoot when left mouse button is clicked
nextTimeToFire = Time.time + 1f / 11f; //shows which is the next time to fire
}
}