Hi Unity Forums! I just stumbled over Csharp getters and setters for the first the ever, as someone used them in a tutorial for creating a healthbar. I have a little bit of background using Java, and c++ so I already understand those getters and setters. Made a calculator etc,etc, nothing huge though.
In One script I have these functions.
public float MaxValue {
get;
set;
}
public float Value
{
set{
fillAmount = Map(value, 0, MaxValue, 0, 1);
}
}
According to a video I watched on this subject
get; and set; is the same as get{return MaxValue}, and set{MaxValue = value;}
But then I get a different result. I don’t want to copy and paste my whole code unless someone asks for it, as it quite big. Basically, the health does not move.
It seems like these type of getters and setters are used to prevent too many variables. Is this true?
Because I do not want to make another post for such a small question I am going to edit in another question right here:
In one of my scripts I have a variable like this:
private Stat health;
I also have the same class public class Stat{}
This class is not attached anywhere (Any object in the game) and that confuses me, yet it still works. What happens when I build the game? So if I have a lots of objects downloaded into my project, and I don’t use them are they also just gonna sit there and take up space when I build the game? I thought only what was in the screen was going to be made as game.