So I have an Object variable which at any given moment equals one of several scripts. In each of these scripts there is a variable with the same name and a different value.
My goal is to get the variable from whatever script is assigned to this Object without making a million if statements.
For example, here is what part of my code looks like:
if (shipname = default001) {
health = default001.health;
manager.barDisplay = health;
}
if (shipname = default002) {
health = default002.health;
manager.barDisplay = health;
}
The above code works, but there are a lot of those. Is there a way to do it without like a gazillion if statements?
I have tried simply putting:
health = shipname.health;
manager.barDisplay = health;
but that just gives me an error saying “‘UnityEngine.Object’ does not contain a definition for ‘health’”
Does anyone know how to make this work?