The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

In my game I had implemented a system in gdscript where you could check what kind of area the player got in contact.
Area2D script:

var areaType = "Item"

or

var areaType = "Bullet"

and I could do something like this in my player script:

func on_player_area_entered():
    if "areaType" in area:
            if area.areaType =="Item":
    # get drop
            elif area.areaType =="Bullet":
    #suffer damage

Now I am trying to repplicate this in c#, how can I do it??

sorry for not perfect english.

Godot version 3.3.3
in Engine by (15 points)

This is not really answer for your question, but in GDS You can check classes itselves, with "is" keyword. If You have class_name Bullet, than You can ask "if area is Bullet"

1 Answer

0 votes
Best answer

I think what you're looking for is Groups. So an "Item" group and a "bullet" group. Any Node can be a in a certain group or groups, then you can check to see if it's part of a group and do something. See this for more details. It's similar to 'tag' in Unity and other engines.

by (52 points)
selected by

I actually figured this myself 10 mins early.
It works.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.