- Home /
Can't click gameobject when over another trigger?
I can't click on my gameobject whenever it's overlapping with a another trigger. You're supposed to be able to drag and drop the gameobject when you click it. As long as I click it without the gameobject overlapping with the other trigger it's fine and I can even pass through the trigger. Can anyone help me with this?
void OnMouseDown()
{
screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
}
void OnMouseDrag()
{
Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) , offset;
transform.position = curPosition;
}
Answer by Andres-Fernandez · May 16, 2014 at 10:59 AM
Try setting the layer of the trigger to IgnoreRaycast.
I tried it ins$$anonymous$$d with RaycastHitTrigger and it worked. Thanks man!
Thanks! But what if we control the area that we are trying to drop, so that we can "if statement" whether if we can place or not? I was planning to use rayCast but if we ignore raycast "the area", how can we solve that?
Your answer
Follow this Question
Related Questions
OnTriggerEnter and IDragHandler 1 Answer
Why is there still drag when drag is 0? 0 Answers
Click but not drag 1 Answer
How do you detect which collider is triggered when you have multiple? 2 Answers
Trigger and Collider Issues 1 Answer