I have read many Unity posts and seem to have the issue still after trying all the suggested solutions. Before I explain my prob, I will give a overview of what I am trying to do, in case there is some other solution that makes more sense rather than what I am trying to do. I have something like this and i've already secceeded to hide lines so now when i display i have this: and I want to show a line when the mouse is clicked .() I tried to add a box collider for each hidden line then use Raycast as a "google advice" . so , this is my code but it dosent work with me ! i'm using debug.log to know where it bugs it just shows : Mouse is down ! Origin: (-1.1, 1.2, -9.7), Dir: (0.0, 0.0, 1.0) UnityEngine.Debug:Log(Object) Code (CSharp): if (Input.GetMouseButtonDown (0)) { Debug.Log("Mouse is down!"); RaycastHit hit = new RaycastHit (); Ray ray = Camera.main.ScreenPointToRay (mouseposition); Debug.Log(ray); if (Physics.Raycast (ray,out hit)) { Debug.Log ("It's working!"); Debug.Log("Hit " + hit.transform.gameObject.name); } } }
How are you hiding the lines? If you're setting the gameobjects inactive their colliders will no longer work.
i made a list having the lines i want to hide then i coded this Code (CSharp): for (int i = 0; i < 16; i++) { lines [i].SetActive (false); } even i tried to change it 'true' to test but it dosen't detect the object.
Oh, of course. You should be using Physics2D.Raycast to raycast 2D colliders. You'll have to change your logic a little bit, as it doesn't return a boolean, it returns a RaycastHit2D. So you should then check if the raycastHit.collider is null.