- Home /
Simple Collision with children of other GameObject doesnt work
So I have this simple problem. I have three objects, all simple boxes and one script. All of them have colliders marked as triggers. First object has this script attached with Second object being Car variable:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LeadObjSkript : MonoBehaviour
{
public GameObject Car;
public void OnTriggerEnter(Collider other)
{
if(other.gameObject == Car)
{
Debug.Log("Car collided");
}
}
}
First object and second object have Kinematic Rigidbodies. Third object is child of Second Object. I am moving First object into Second one, script works. But when I move First Object into Third one, no Debug.
Is there any way to have it so that when First object collides with children of second object that it counts as collision with that Second (parent) object?
Answer by _samuel12345 · Aug 11, 2020 at 02:33 PM
You probably would have to check independently for a collision with the third object and then run the same bit of code you would as if it had collided with the second object. So, something like this:
public class LeadObjSkript : MonoBehaviour
{
public GameObject Car;
public GameObject thirdObj;
public void OnTriggerEnter(Collider other)
{
if(other.gameObject == Car || other.gameObject == thirdObj)
{
Debug.Log("Car collided");
}
}
}