Return a value for a class?

So I have a serializable class, and I want to be able to get a value simply by referring to the object. At the moment I have to refer to specific values like “” when I’d rather just say “statistic”.

How might I go about returning the object’s value?

The Vector3 struct is always a struct and a class is always a class. You can implement implicit casting operators, however that should only be done when it’s an obvious conversion. The Vector2 / 3 / 4 struct only have a conversion between each other so a Vector2 can be used as Vector3.

Implicit casting only applies when it’s obvious for the compiler to which type it should be converted.


public class Statistic
    public float total;
    public static implicit operator float(Statistic aObj)

An instance of that class could be converted implicitly into a float value:

Statistic statistic = new Statistic(); = 5;
// ...
float f = statistic;
// f would be "5"

However, in this case it’s not really obvious and an conversion like that isn’t convenient and shouldn’t be implemented like that. Implicit casting isn’t ment for laziness but when one type can be used like another. Another example is “Color” and “Color32”.