- Home /
Issues with collision detection
i have 2 objects... one is named Block and the other is Hole... The block has 4 child empty objects that have box colliders with custom sizes, according to need... The hole object has a rigidbody, with gravity=false, and a box collider with isTrigger=true... for each child object in the BLOCK object, there is a code for movement when mouse is clicked on it... When the block enters the hole object, it does not trigger the OnTriggerEnter function... what do i do?
using UnityEngine; using System.Collections;
public class StopBlockMovement : MonoBehaviour {
// Use this for initialization
void Start(){}
// Update is called once per frame
void Update()
{
}
void OnTriggerEnter(Collider other)
{
Debug.Log("a");
}
I tried this on script on both items does not show collision...
script for movement in the child empty objects is:
bool pressed=false;
// Use this for initialization
void Start(){}
// Update is called once per frame
void Update()
{
if(pressed==true)
{
transform.parent.Translate(Vector3.down*Time.deltaTime*2);
}
if(transform.parent.position.y<-6.5)
{
Destroy(transform.parent.gameObject);
}
}
void OnMouseDown()
{
pressed = true;
}
Answer by shraa1 · May 12, 2014 at 02:46 PM
actually i got it answered myself... i just added rigid-bodies to the child objects... and the first script in each child... thanx for the help, though :)
Answer by VIPINSIRWANI · May 09, 2014 at 05:27 PM
First you should give the tag to other object and after that Once try with this Code may it will help you
void OnTriggerEnter(Collider cldr)
{
if(cldr.gameObject.tag == "whatever you gave" )
{
Debug.Log("Trigger Enter is Working");
}
}