© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
8 replies
Raptorini

✅ How to reference gameObject in OnCollisionEnter2D?

public void OnCollisionEnter2D(Collision2D col)
    {
        if (col.gameObject.tag == "wall_up")
        {
            Debug.Log("Collision detected!");

        }
    }
public void OnCollisionEnter2D(Collision2D col)
    {
        if (col.gameObject.tag == "wall_up")
        {
            Debug.Log("Collision detected!");

        }
    }

I don't want to detect collision of the game object the script is tied to, I want to detect collision of an instantiated object called _cell. How do I reference _cell in the collision function?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Help about OnCollisionEnter2D
C#CC# / help
2y ago
❔ how to reference a variable in another script?
C#CC# / help
3y ago
❔ Flip GameObject with Parent
C#CC# / help
3y ago
How to Correctly Reference a Method in App.xaml.cs
C#CC# / help
13mo ago