I have 2 objects that are spawning randomly on the plane, a rock and a tree, both have colliders and rigidbodys, they are both tagged as “breakable”, but, when im playing and i click on a tree, in the console it says “hit” and “breaking…” as it should, but when i click on a rock nothing happens. any help is appreciated!
I have this code inside my player script:
void Attack()
{
if (Input.GetButtonDown("Fire1"))
{
RaycastHit hit;
if (Physics.Raycast(cam.transform.position, transform.TransformDirection(Vector3.forward), out hit, attackDistance))
{
Debug.Log("Hit");
if(hit.collider.tag == "Breakable")
{
ObjectHealth objHealth = hit.collider.gameObject.GetComponent<ObjectHealth>();
objHealth.TakeDamage(25);
Debug.Log("breaking...");
}
}
}
}