what I’m trying to do is to destroy all objects ray went through them in a range of 6m and not just 1 object (first).
I know I should use RaycastHit
but this gives basic idea what I’m trying to achieve
and OFC this is not on Update function so it’s only 1 go to find them all.
RaycastHit RayHits;
if (hit[0]){
ray = new Ray ((new Vector3(transform.position.x, transform.position.y+2, transform.position.z)),
transform.TransformDirection(Vector3.forward));
Debug.DrawRay ((new Vector3(transform.position.x, transform.position.y+2, transform.position.z)),
transform.TransformDirection(Vector3.forward*6), Color.red, 5f);
if (Physics.RaycastAll(ray, out RayHits, 6f)){
Destroy(RayHits.collider.gameObject);
}
}