Is there a way two make two trigger gameObjects collide?

Deadly 提交于 2019-12-11 03:12:07

问题


This is for a 2D game.

I have a Player who can shoot trigger projectiles(with a trigger collider) and Enemies that can do the same. When a Player projectile collides with the Enemy, stuff happens and vice versa. However, when the Player projectile and the Enemy projectiles collide, they just ignore collision, go through each other, and nothing happens. They also have a Rigidbody2D with continuous collision detection.

Is there a way to make it so something happens when these two gameObjects with trigger colliders touch?

Here's what I've got for the Enemy projectile script:

void OnTriggerEnter2D( Collider2D other ){
    if (other.gameObject.name == "Ground"){ 
        Destroy (gameObject);
    } 
    else if (other.gameObject.name == "Player"){
        other.gameObject.GetComponent<RControlScript>().RHealth = other.gameObject.GetComponent<RControlScript>().RHealth - damage;
        Instantiate(transformInto, gameObject.transform.position, gameObject.transform.rotation);
        Destroy (gameObject);
    } 
    else if(other.gameObject.name == "Shot"){
        Destroy (gameObject);
    }
}

"Shot" being the name of the Player projectile being the gameObject not colliding with the Enemy projectile.


回答1:


Yes.

Here is a graph that tells you what collides with what in Unity3d.




回答2:


Ok, turns out two trigger colliders do in fact collide. My problem was that the projectiles instantiated were clones, therefore its name = "Shot(clone)". Had to change that in order to make things happen.



来源:https://stackoverflow.com/questions/27009055/is-there-a-way-two-make-two-trigger-gameobjects-collide

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!