Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
275 views
in Technique[技术] by (71.8m points)

function - Problem with trigger in OntTriggerEnter2D in unity

second objectfirst objectI have a two objects, both of them have : rigidbody2D of type dynamic, collider2D set to trigger, same layer, same Z position. But they do not collider with each other. One of them has a simple script attached, which contains function OnTriggerEnter2D, which just debug.log some message. As you can guess the console doesn't print the message. No errors tho. Please help! I've also tried to restart unity, even the PC - doesn't work as well. function :

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

public class Enemy : MonoBehaviour
{
    private void OnTriggerEnter2D(Collider2D collision)
    {
        Debug.Log("DUOA");
    }
}
question from:https://stackoverflow.com/questions/65852584/problem-with-trigger-in-onttriggerenter2d-in-unity

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Have a look at the Collision action matrix, you will not receive a trigger call from two dynamic Rigidbodies that both have a trigger collider component.

Change one of the Rigidbody types to Kinematic, which should resolve your issue.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...