Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

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:
    29,567
  4. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    2,798
    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:
    67
    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
     
unityunity