Input.mouseposition in canvas.
Hello everyone. I got such a structure of project: Canvas -> 2 panels (up and down) -> in up panel ive got 5 canvas that enable and disable from code. In down panel i just got 5 buttons(clicking button -> changing canvases in up panel)
I started to do slide because in 1 of canvases i need sliding(android). Spend some time, done it. Got another problem. My sliding hitting whole screen. So if i starting clicking on another button it starts the sliding but at the same time changing canvas so my sliding unstoppable.
So the main problem is: how to track down does my click belongs to any canvas. I need to execute some code only if i click in my canvas.
Tried to raycast2d, but it shows only if hits. And it hits anyway - it hits button or canvas, dont know how to get the target of hit.
I can stop sliding when changing canvases, but i would like if i can only execute some code if i hit only my canvas. So my question like how to know raycast target or about it.
Searched a lot of links and decided create my own theme...
Tried to do screen for you understand me, sorry, my first theme
Answer by LisLite · Jan 10, 2016 at 05:17 PM
Nah, found the solution.
if(Input.GetMouseButtonDown(0))
{
PointerEventData pointer = new PointerEventData(EventSystem.current);
pointer.position = Input.mousePosition;
List<RaycastResult> raycastResults = new List<RaycastResult>();
EventSystem.current.RaycastAll(pointer, raycastResults);
if (raycastResults.Count > 0)
{
if (raycastResults[0].gameObject.name == "Mobs")
{
Sliding = true;
}
}
}
Seems to be working.