I have spawned cubes that I want destroyed when they are line with my raycast ray but I do not know what GameObject to put in Destroy (…).
Teacher said I need to pass Destroy(…) a GameObject instance which I can get from a RaycastHit object but I don’t really know how to do this.
This is what i have so far:
if (Input.GetMouseButtonDown(0)) {
Ray ray = cameras.ScreenPointToRay(Input.mousePosition);
Debug.DrawRay(ray.origin, ray.direction*5f, Color.red,2f);
RaycastHit hit;
bool isHit = Physics.Raycast (ray, out hit, 10f);
if (isHit) {
Debug.Log ("We just hit " + hit.transform.name);
Destroy (???);