-
Notifications
You must be signed in to change notification settings - Fork 209
Description
Hello Ryan! I'm probably very late but amazing sharing; it completely changed the way on how I worked with Unity and this is so beneficial. Thank you!
I am thinking of adding a set to the Value property so that when other scripts assign a value, the Value property can receive it, then modify, based on whether UseConstant is true or false, ConstantValue or Variable.Value.
The property will look like this:
public float Value
{
get { return UseConstant ? ConstantValue : Variable.Value; }
set
{
if (UseConstant)
ConstantValue = value;
else
Variable.Value = value;
}
}
And in other scripts, one can simply do something like this:
public FloatReference hp;
.
.
.
hp.Value = 10;
So far, the only implication I have seen was that setting via a FloatReference, you may be expecting a variable to get updated, but if UseConstant is true, the constant is updated and not the variable. So, for example, if you decrement the player's HP and the HP is of type FloatReference with UseConstant set to true, then this may not update the UI for the HP (e.g. say a HP bar) which depends on a FloatVariable to determine the fill amount, making others think that the player's HP is not decreasing.
But then if such a case happens, FloatVariable should be used to adjust HP instead of FloatReference, which will make it clear to the team that modifications made to it will be clearly shown.