Find script inherits from a specific base class?
I have a grid for a map-making game. In it I have a Tile class, and many variants that inherit from Tile. Would it be possible to, with access to the gameobject that owns one of these variant scripts, to get that script (the one that inherits from Tile)?
Answer by streeetwalker · Apr 12, 2020 at 08:20 AM
Hi @Propellent, in a script this.gameObject or simply gameObject references the object the script component is attached to. From there, it's not clear what you want to do.
From the parent Tile class, you want to find all objects with script's that inherit from that?
Yes that's exactly what I'm trying to do! I've been told that I could also use Send$$anonymous$$essage
OK. if you can get a list of all objects, you can go through them one by one and use typeof(Derived Class).IsSubclassOf( typeof( Base Class )) will be true if the object's Derived class has inherited from base class. If the objects in the list have multiple scripts on them, you're going to need to iterate though those and put that test int he inner loop.
Your answer
Follow this Question
Related Questions
What is the easiest way to enable 2D isometric grid-based pathfinding? 2 Answers
Delete a specific GameObject (with tag) on a Specific Vector2 Location 0 Answers
Text on grid games 0 Answers
Grid based movement, sprite change to simulate movement 0 Answers
My collisions dont detect in gridbased system (check if in certain area) 0 Answers