c# - How to check if the finger is touching area where object instance exist? -
there way place objects on surface swiping finger on screen (thanks @ryemoss answer here )
the question how avoid placing objects on top of each other - how can check if finger touching area there object instance exist, , place new objects if area empty?
the answer i'm looking should include possibility make objects overlap bit if needed (touch each other's borders).
here snippet unity samples in sdk (check here) checks if existing placed marker (gameobject) touched during touch event:
touch t = input.gettouch(0); vector2 guiposition = new vector2(t.position.x, screen.height - t.position.y); camera cam = camera.main; raycasthit hitinfo; if (t.phase != touchphase.began) { return; } if (m_selectedrect.contains(guiposition)) { // nothing, button handle } else if (physics.raycast(cam.screenpointtoray(t.position), out hitinfo)) { // found marker, select (so long isn't disappearing)! gameobject tapped = hitinfo.collider.gameobject; if (!tapped.getcomponent<animation>().isplaying) { m_selectedmarker = tapped.getcomponent<armarker>(); } }
what need handled
if (physics.raycast(cam.screenpointtoray(t.position), out hitinfo))
Comments
Post a Comment