Detect collision with child object?

Hi
I am making my first game with unity and I have a script to crush the player. In this script I also have a collision detecting function.

here is my script:`using System.Collections;

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class CrushingThePlayer : MonoBehaviour
{

public bool isCollidedWithWall = false;
public bool isCollidedWithCube = false;

public void OnCollisionEnter(Collision collision)
{
    if (collision.gameObject.name == "Wall")
        isCollidedWithWall = true;
    else if (collision.gameObject.name == "MovaeableCube")
        isCollidedWithCube = true;

    if (isCollidedWithWall && isCollidedWithCube)
        SceneManager.LoadScene("Scene1");
}

public void OnCollisionExit(Collision collision)
{
    if (collision.gameObject.name == "Wall")
        isCollidedWithWall = false;
    else if (collision.gameObject.name == "MoveableCube")
        isCollidedWithCube = false;
}

}

I want the same script, but with a child that detects the collision.
I now have if (collision.gameObject.name == “MoveableCube”) but want to do it with a child of the cube

if someone knows how to do this please tell me.

You can try

gameObject.transform.GetChild(int index)

does exactly that. ‘index’ stands for the index of the child/childrenren of the game object. So in your case, if you only have one child, then you’d do:

if (collision.gameObject.transform.GetChild(0).name == "MovaeableCube")
{
       isCollidedWithCube = true;
}

The 0 in GetChild(0) means that the child of the game object you want to access to is the first child of that game object.