Hello,
for logical operations I have class called Brain
and for each individual puzzle i have individual child classes of brain
for example
public class Puzzle 1: Brain {}
now I also have trigger objects, and trigger objects invoke function called “StartBrain” that is part of parent class on a game logic object.
Because I don’t know what will be the name of the script that is attached to logic object (Puzzle 1 or Puzzle 2), I use target.sendmessage(“StartBrain”, Parameters) to invoke this function on an object.
Now I was wondering if it is possible to use polymorphism with something like this.
target.getcomponent().MyFunction();
and target has child class attached to it, so that I can call a child class as a parent class, and invoke the method in parent class.
I know unity uses something similar with colliders, where parent Collider class can be used for collision detection, regardless of whether object has child classes like boxcollider or sphere collider. But I don’t have strong enough grasp of polymorphism theory to figure out how to do it myself.
If anyone can help me with this, it would be awesome