Generation

generate functionThu, 01 Jun 2023

unity raycast to mouse position

//code for raycast Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo; Physics.Raycast(ray, out hitInfo); GameObject hitObject = hitInfo.transform.root.gameObject; //code for getting a paren'ts transform private GameObject GetRoot(GameObject gameObject) { Transform t = gameObject.transform; while (t.parent != null) { t = t.parent; } return t.gameObject; }

Want to kickstart your project?Use the new AI Studio to create your code