Hello,
can I make a property of an object return a static value if the object itself is null? I’m trying to use a component system for some of my game objects and I figured it’d be convenient if the property just returned the value 0 if the object didn’t exist (if my spaceship didn’t have a booster, I don’t want to check for missing boosters all the time) It’d be far more convenient if booster power requests just returned 0.
My current attempt at coding this looked like this, but it returns null reference errors if I actually try to access the properties.
private bool initialised = false;
[SerializeField, Tooltip("maximum boosting Time for BoosterDrive ScriptableObject"), Range(0f,1000f)] private float maxBoost = 100f;
public float MaxBoost
{
get
{
if(this == null)
{
return 0f;
}
else return maxBoost;
}
}
Honestly no clue if this is even possible, but it’d be very neat if it was.