U
U
userpyy2021-04-24 13:54:03
Unity
userpyy, 2021-04-24 13:54:03

Why doesn't OnCollisionEnter/OnTriggerEnter work?

I created an empty project. I added a cube and threw a RigidBody and a Box Collider on it. I added a second cube, and threw a Box Collider on it.
I made a script and hung it on the first cube (I also tried on the second one):

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

public class Test : MonoBehaviour
{
    void OnCollisionEnter()
    {
        print("hit");
    }
}

I have already tried various options (Also hung RigidBody and Box Collider on everything possible)
I also tried using OnTriggerEnter by turning on (and even turning off) is Trigger but that doesn't work either.

Can someone throw off the simplest example with these functions (Scene)? I did not find it on the Internet.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
Herman Coffman, 2021-04-26
@Gera01

1. If 2d game - need OnCollisionEnter2D
2. need rigetbody 2d or normal, depending on the collider
3. Need input arguments.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question