Godot how to check type of area2D in c#?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By LNTMRT

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.

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”

Inces | 2021-09-22 10:36

:bust_in_silhouette: Reply From: Satscape

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.

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

LNTMRT | 2021-09-23 01:32