- Home /
OnTriggerEnter() problem
I've been searching the internet for an answer and have not yet found one so I thought I'd ask you guys.
I am dragging 2D tiles through 3D cylinders who's trigger is clearly intersected by the tiles. When the tile enters the trigger, it should click into place with the cylinder, but it doesn't. "working" pops up only when the tiles are instantiated, but if I drag them through the cylinder after that, nothing happens.
Please don't refer me to another Community Answer because I've seen everyone on the topic. Thank you in advance!
using UnityEngine;
using System.Collections;
public class ClickInPlace : MonoBehaviour
{
void OnTriggerEnter(Collider other)
{
Debug.Log ("working");
other.gameObject.transform.position = new Vector3(transform.position.x, transform.position.y, 0f);
}
}
I just successfully tested your script
$$anonymous$$ade a 3d cylinder and 3d plane,
Attached the script on the plane
Turned on the IsTrigger property of the plane's mesh collider
Gave the plane a rigidbody and turning on Is $$anonymous$$inematic and turning off Use Gravity
Dragging the plane near the cylinder (note: moving the cylinder will have no effect)
Try Debug.Log(gameObject.name+" "+other.gameObject.name); to see if they actually collide at the start. $$anonymous$$ake sure one of them has a rigidbody and IsTrigger is on. Also make sure you are using 3D colliders for both since 2D colliders and 3D colliders cannot collide with each other.
Answer by MichaelBoguslaw · Mar 03, 2015 at 09:04 AM
I fixed the problem during one of those spontaneous "aha!" moments. For anyone who by chance is stumped with this specific scenario, I'll explain my problem:
The Drag script that told the tile to be at the mouse overrode the SnapInPlace script that told it to go to the location of the dot. I am using the OnTriggerStay() function as a temporary solution.