codeswan blog

Game Dev: Properties

tldr: they’re called properties

You know the most frustrating thing ever as a dev? (Even more frustrating than having to name things?)

Not knowing the right search terms.

I was trying to figure out how to have one of those little customizable fields in the Unity component editor. You know, the ones where you can enter a value specific to each object, and easily access it in your scripts.

Parameters? No.

Input fields? Nada.

Variables? Ughhhhh no.

All of the above come up with some entirely different search results than what I actually wanted.

Finally… properties!

Yes I feel dumb.

Anyways. All you have to do is create a public property – for example, public int points; … and voila! A customizable property that you can access from within the object.

And if you want to access it elsewhere? gameObject.GetComponent().propertyName; So easy.

And now my pickups have different point values associated with each one!

Leave a Reply

Your email address will not be published. Required fields are marked *