I am trying to lose damage once when i click using raycast and i use the debug as a test, and with one click it displays 5 debug logs and loses lots of health…
public class Crosshair : MonoBehaviour
{
public float range = 8.0f;
public float damage = 10.0f;
void Start ()
{
Screen.showCursor = false;
}
void Update ()
{
Screen.lockCursor = true;
if(Input.GetMouseButton(0))
{
Fire();
}
}
void Fire ()
{
Ray ray = new Ray(transform.position + transform.forward /2 , transform.forward);
RaycastHit hit;
if(Physics.Raycast(ray, out hit, range))
{
if (hit.collider.gameObject.tag == "Destructible")
{
Debug.Log("hi");
hit.collider.gameObject.GetComponent<Destructible>().ApplyDamage(damage);
}
}
}
}