Debug.Log issues

Good Morning guys,
i have a problem with my
`Debug.Log(“Word”);

This not working and i have checked all my packed and extensions, idk what is the problem.
Here is my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Collision : MonoBehaviour

{
    void OnCollisionEnter2D(Collision2D other)
    {
        Debug.Log("Pew");
    }
}

I hope anybody can help me and sorry my englisch is not so good I’m learning.

Happy coding
Florian

Hi Florian,

If the “Pew” message does not appear in your Console, there are multiple things you could check:

  • Collisions happen between colliders. Check if your game objects have got Collider2D components attached to their Inspector.
  • Scripts must be attached to a game object. “Pew” appears only if your Collision script is attached to a game object involved in the collision.
  • Make sure the script has been saved.
  • The messages must be enabled in your Console.
  • In rare cases, the name Collision causes problems because it might already exist in the UnityEngine namespace. Are there any error messages in your Console?

Please let me know if any of this helped. :slight_smile:

By the way, I can also speak/write German if you prefer explanations in that language.

Just a note: Don’t call your component Collision. Unity has an object called Collision and you will do yourself a huge favour by not naming your own class that, too.

Oh thank, but i will learn englisch :slight_smile:

My failure was, I hide the informationpoint.
Screenshot 2023-11-22 133725

Sry, what are you mean with rename the class? Do you have a screen for me?

He meant the same as I. Since the name Collision already exists in this context, it is advisable to rename the class and the file.

public class Collision : MonoBehaviour could be changed to public class CollisionHandler : MonoBehaviour. The file must be renamed to ‘CollisionHandler.cs’ because that’s a requirement by Unity.

If you follow a course and the instructor uses the name Collision for his own classes in his project, you use CollisionHandler for your own classes in your project. If the instructor uses Unity’s Collision class, you too use Unity’s Collision class.


See also:

1 Like

Perfect. Very thanks for the information.

Have a good day and happy coding.

Oh, I didn’t even see you had that in your list. My bad

No worries. I just wanted to be faster than you for once. That’s why I mentioned it. :wink:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms