Search Unity

  1. We would like to hear your feedback about Unity and our products. Click here for more information.
    Dismiss Notice

Issue with Collision

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

  1. Torbaz

    Torbaz

    Joined:
    Apr 17, 2019
    Posts:
    1
    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:
    137
    For a start it should be...

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