One of the most frequently needed things is information about objects the player collides with. Typically some kind of attribute would help to indicate that the object we collided with is breakable or walkable or something.
What is the best way to do this? Creating a script to attach to these objects for the sole purpose of containing and returning a constant seems utterly excessive. I am wondering if there is a different way to assign custom attributes to a gameObject.
And, no, Tag will not work because I will need more than one attribute.
of-course Tags can help you in this, lets understand this with an example, say we have a pillar that is breakable then set its tag like Pillar_Breakable, then your script will look something like this
if(collidedObject.tag.Contains("Pillar")){ // First check if we have a collision with pillar
if(collidedObject.tag.Contains("Breakable")){ // Now check if this pillar is breakable
// Break this pillar
}
}
Please don’t just copy paste above code as it is Untested
What if I need the pillar to be breakable and climbable? Tags are completely useless for that purpose, because every gameObject can contain only one Tag. Unless you want to create a million different tags to represent all possible combinations of attributes. Not to mention that all these string-based tags are not exactly efficient.
What Unity should really offer is a 64-bit custom value that is part of every gameObject. That way we could create bit flags and attach them directly to any object, retrieving them very quickly. I am really surprised this does not exist.