- Home /
find prefabs that extend Base Class c#
hey i would like to know how to find all my prefabs that extend my base class
eg
im making a 2d game and have tones of tiles i load my level from an image where i find the pixel on the image and load the tile thats spawn colour is the same as the pixel
right now im defining the tile and there spawncolours in a script
for example public class objects { public Transform rockObject; public Color rockObjectColour;
public Transform grassObject;
public Color grassObjectColour;
public int grassSpawnNumber = 1;
public Vector3 grassRandomOfset = new Vector2(0,0);
}
public objects Objects;`
and to spawn my colours im using
if(objectColours[x+z*levelWidth] == Objects.rockObjectColour)//if the selected colour = the colour of the rock { currentObject = Instantiate(Objects.rockObject, new Vector3(x,0,z) , Quaternion.identity) as Transform;
}`
what i need to do is instead of having to define all my tiles and their colours in the script have a base class
public abstract class Tile : MonoBehaviour {
Public String TileName = rocktile;
Public Color TileColour = red;
}
and attach this it all my tiles i will have and make them all prefabs. so instead of having to define them i could just say something like: If (objectColours[x+z*levelWidth] == Tiles.red) then spawn rock
Thanks for Reading ~Scott
Your answer
![](https://koobas.hobune.stream/wayback/20220613172851im_/https://answers.unity.com/themes/thub/images/avi.jpg)