This is probably a really dumb question, but I’m completely stumped at this point. Here is the functionality I need to create:
- Load multiple GameObjects, which have an attached script that has stat and
function information. - Get data out of that attached script and then use it.
Now, I’ve been able to do this in a singular case via:
var Player1: GameObject;
function PrintDatas(){
var p1Stats = Player1.GetComponent(MageScript);
Debug.Log(p1Stats.Health);
}
Where I’m having issues, however, is if I want to use a different character - a Fighter for example. The fighter is unlikely to have the “MageScript” component, since that contains spells and stats for the Mage.
So, how would I access that script without being specific to the name? I tried substituting a string, but was not successful.
var statsString:String = Player1.name+"Script";
Resulting in the error: ‘Health’ is not a member of UnityEngine.Component’.
My other idea was to create a uniform “stats” script and save it as part of a prefab on the character game objects, but of course it’s the same script on each, so that doesn’t work for me - I need different functions and values.
Any help would be appreciated.