- Home /
Trigger not reaction to code, even tho there is collision detection
Hey everyone, I'm having trouble getting my trigger to react. Can someone tell me what is wrong with this code? I'm attempting to break my character free from the parent object and fall towards the ground as a non kinematic rigidbody.
Putting in for example Application.LoadLevel(2); works fine, but I can't get the below commands to work.
using UnityEngine;
using System.Collections;
public class CollisionCheck : MonoBehaviour {
void OnTriggerEnter (Collider other)
{
other.transform.parent = null;
other.gameObject.rigidbody.isKinematic = false;
}
}
I get no compiler errors, just no reaction when entering the trigger. Help is much much appreciated !
Answer by amazingdude123 · Oct 31, 2014 at 06:43 PM
Do you have the object tagged as other? Probably best to change the tag of the object to something recognisable so it doesn't get confused with other game object. Also do you have the collider on the object and have the trigger box ticked?
Answer by vrsponginator · Oct 31, 2014 at 06:28 PM
I solved the problem by encasing the code in an if statement: (C#)
using UnityEngine;
using System.Collections;
public class CollisionCheck : MonoBehaviour {
void OnTriggerEnter (Collider other)
{
if(other.gameObject.name == "NameOfPlayerOrObject")
{
other.gameObject.rigidbody.isKinematic = false;
other.transform.parent = null;
}
}
}
In case anybody needs it.
Your answer
![](https://koobas.hobune.stream/wayback/20220613170429im_/https://answers.unity.com/themes/thub/images/avi.jpg)