c# - Unity3D on Click ignore all colliders accept the one on specific layer -


i'm trying make simple drag , drop game have objects can picked , if left above 1/2 of screens height fall down high fall if let them go below half of screen stay there. 2d game , give illusion of depth.

this image of thing make enter image description here

currently can move blue bucket bottom. if lift bucket above polygoncollider fall down edge collider 4. when leave somewhere withing polygone colider set object kinetic wont fall give illusion placed on ground.

my problem colliders of bucket use detect click on it, overlap polygoncollider. , can object on top , sometime polygoncollider , , if polygoncollider on top can not lift object. there way ignore on click layers except pickebleobject layer use identify objects can picked ?

edit: here objectcontroller script

public layermask interactlayers; public layermask ignoredcolliders; public action<gameobject> ondrag; public action<gameobject> onland; private rigidbody2d objrb2d; private vector2 mousepos; private bool isonfloor = false;   private void start() {     transform.position = new vector3 (transform.position.x, transform.position.y, transform.position.z - 0.1f);     ignoredcolliders = ~ignoredcolliders;     objrb2d = transform.getcomponent<rigidbody2d>();     objrb2d.gravityscale = gamemanager.instance.globalfallingspeed; }   private void onmousedown() {     objrb2d.iskinematic = true; }  private void onmousedrag() {     mousepos = camera.main.screentoworldpoint (new vector2 (input.mouseposition.x, input.mouseposition.y ));     //limit elements cant moved out of scene.     float horizontalclamp = mathf.clamp (mousepos.x, cameracontroll.instance.camtopleft.x, cameracontroll.instance.cambottomright.x);     transform.position = new vector3 (horizontalclamp, mousepos.y, transform.position.z);      //check under mouse.     raycasthit2d ishoveringover = physics2d.raycast(transform.position,  transform.transformdirection (vector3.down), 0 , ignoredcolliders);     if (ishoveringover.transform != null) {         if (gamemanager.instance.groundcolliders.value == layermask.getmask (layermask.layertoname (ishoveringover.transform.gameobject.layer)))             isonfloor = true;     }else isonfloor = false;       raycasthit2d hitcolider = physics2d.raycast(transform.position,  transform.transformdirection (vector3.down), mathf.infinity , ~ignoredcolliders);      #if unity_editor     if (hitcolider.collider != null) {         debug.drawline( hitcolider.point, transform.position, color.magenta);     }     #endif }  void onmouseup() {     if (!isonfloor) objrb2d.iskinematic = false; }  void oncollisionenter2d(collision2d coll) {     //debug.log(coll.gameobject.transform.name); } 

if using physics raycast in drag-n-drop logic take @ documentation, there find topic layermask , raycasting.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -