- Home /
Create a Serializefield for Object Properties
Greetings all.
What I a looking to do is create a Seralizefield with which I will be able to assign objects in the editor a certain type which will determine their attributes. In this case I have buildings and a few variables I want to assign a default when they're populated in the editor.
The bar would basically look like
-Building 1
-Building 2
-Building 3
When you assigned the object one of these building types, it's cost (and other variables, but just leave it as an int for now) would change to reflect that current state. Is there an easy way to do this and put it in a Serializefield?
Thanks.
Answer by fdz_ · Dec 09, 2017 at 02:11 AM
Sorry. I don't know if I understood. You want to do something like this?
[System.Serializable]
public class Building
{
public GameObject buildingPrefab;
public int cost;
}
public class Buildings : MonoBehaviour
{
public Building[] buildings;
}
It's assigning the values to the object itself. The script on the object, when turned to "Building 1" or "Building 2" would change the cost of it. This isn't a spawner, it's the object itself.
Ok. $$anonymous$$aybe you should use some CustomEditor or CustomPropertyDrawer.
This one is a cool link: