Question by
nshazwani94 · Aug 10, 2018 at 03:38 AM ·
click objects
click gameobject in specefic panel
Hi, I am working on a screen that has a list of friends. The problem is I want to click on this Game Object( 1 game object 1 friend) inside this specific panel ONLY (blue color). Before this , I tried, but it can clicked anywhere not specifically inside this panel. And this game object is a prefab. sorry, I am a newbie in Unity
void Update () { if (Input.GetMouseButtonDown(0) ) { try { Debug.Log("Clicked."); var ray = Camera.main.ScreenPointToRay(Input.mousePosition); Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector2 mousePos2D = new Vector2(mousePos.x, mousePos.y); RaycastHit2D hit = Physics2D.Raycast(mousePos2D, Vector2.zero); if (hit.collider.tag == "Panel1") { if (hit.collider.tag == "Friend") Debug.Log("---> Hit: "); } Canvas.SetActive(false); Canvas2.SetActive(true); } catch (Exception ex) { Debug.Log(ex); } } }
Please refer to the picture as reference. Thankyou !
capture.png
(16.8 kB)
Comment
Your answer
Follow this Question
Related Questions
Changing scene by clicking on a game object 1 Answer
Switching Player's Camera By Clicking An Object 0 Answers
Problems with simple cube click 1 Answer
Cant click on GamObject 1 Answer