Search Unity

Bug Pls Help My collision code wont work

Discussion in 'Scripting' started by SMagic702, Sep 26, 2022.

  1. SMagic702

    SMagic702

    Joined:
    Oct 9, 2021
    Posts:
    3
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class PlayerCollision : MonoBehaviour
    4. {
    5.  
    6.     void OnCollisionEnter(Collision collisionInfo)
    7.     {
    8.         if (collisionInfo.collider.tag == "Enemy")
    9.         {
    10.             Debug.Log("WE Hit balls");
    11.         }
    12.  
    13.     }
    14.  
    15. }
     
  2. SMagic702

    SMagic702

    Joined:
    Oct 9, 2021
    Posts:
    3
    Basically i just get these warnings
    The referenced script (Collision) on this Behaviour is missing!
    and
    The referenced script on this Behaviour (Game Object 'player') is missing!
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,695
  4. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,859
    I have a feeling the names of your script files don't match the names of the classes inside them.
     
    TheDevloper likes this.
  5. TheDevloper

    TheDevloper

    Joined:
    Apr 30, 2019
    Posts:
    69
    yes that's it 100%

    1- Rename you script in the editor
    2- rename your class
    3- save and test
     
  6. SMagic702

    SMagic702

    Joined:
    Oct 9, 2021
    Posts:
    3
    Ok thanks guys