Search Unity

Issue with Collision

Discussion in 'Editor & General Support' started by Torbaz, May 5, 2019.

  1. Torbaz

    Torbaz

    Joined:
    Apr 17, 2019
    Posts:
    3
    c#
    I want to be able to detect when an there an attack hits another object. There is nothing being detected when any collisions happen. I would like it to only be for a specific trigger but at the moment just getting collisions would be good.

    Code (CSharp):
    1.     void OnCollisionEnter(Collision collisionInfo)
    2.     {
    3.         if (collisionInfo.collider.tag == "Player")
    4.         {
    5.             Debug.Log("Collision");
    6.         }
    7.     }
    I have also tried with this:
    Code (CSharp):
    1.     void OnCollisionEnter(Collision collisionInfo)
    2.     {
    3.  
    4.             Debug.Log("Collision");
    5.  
    6.     }
     
    Last edited: May 5, 2019
  2. SamohtVII

    SamohtVII

    Joined:
    Jun 30, 2014
    Posts:
    370
    For a start it should be...

    if(collisionInfo.gameObject.tag == "Player") {