Hey folks,
I’m sure I’m misunderstanding something fundamental here, and hope someone can help me out.
Given these classes:
public class MobBaseClass : MonoBehaviour
{
private int hitPoints;
public string GetInfoString()
{
return "HP: " + HitPoints;
}
}
public class Dwarf : MobBaseClass
{
}
public class Orc: MobBaseClass
{
}
I’m spawning GameObjects in the game of both Dwarf and Orc types, and I’m trying to set up information printing to screen when I do a mouseover of anything that inherits from MobBaseClass.
My GUIManager script gets passed an Orc or Dwarf via an event, and then I’m trying to then access the MobBaseClass method GetInfoString() and use that to populate my GUIText.
My current attempt looks like:
//Tooltip if mouse is over mob
if (mobForTooltip != null)
{
mobInfoText.text = mobForTooltip.GetComponent(MobBaseClass).GetInfoString();
}
… which bombs. I’ve also tried casting mobForTooltip from a GameObject to a MobBaseClass, and that doesn’t work.
I feel like I’m missing something fundamental in the relationship between GameObjects, attached scripts, and their classes. Any help would be appreciated.