- Home /
problem with get{} and set{}
I wrote some code like this and make it a prefab:
class monster:monobehaviour{
private int _health;
public int health
{
get{return _health;}
set{_health = value;}
}
}
the problem is : I can't find a way to fill the "health" in the inspector panel of this prefab,is there a solution? (or I must erase the accessors and make _health public?)
Comment
Answer by Bunny83 · Apr 18, 2013 at 10:07 AM
properties aren't serialized by Unity as well as private variables. However you can add the SerializeField attribute to your private variable and it will be serialized and show up in the inspector.
[SerializeField]
private int _health;
Your answer
![](https://koobas.hobune.stream/wayback/20220613100540im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Using scripts inside an Array 1 Answer
How do I set and get the position of a object? 3 Answers
PlayerPref/PlayerPrefsX why not able to store boolean values? 1 Answer
c# setter/getters 1 Answer
Public variable hidden in the inspector 2 Answers