how to detect which gameobject is clicked
问题 I want to know which gameobject is clicked with mouse on a 2D project I used void Update() { if (Input.GetMouseButtonDown(0)) { clickTime = DateTime.Now; mousePosition = Input.mousePosition; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction); if (hit != null && hit.collider != null) { } } } but it never goes in the second if condition EDIT: I am working on a single script and access all gameobject from there using