Comparing game objects types

I’ve got two variables in my script, one holds the prefab for a building i’m trying to build and the other holds an instance of a building that may or may not be the type of building I’m trying to build. I’ve done some searching around on just about every phrasing of this but I can’t seem to find a way to check if a game object is an instance of a particular prefab. Can anyone point me in the right direction? Thanks for your time!

Add a public enum to your script:

public enum BuildingType {
    house = 0,
    office = 1,
    skyscraper = 2
}

Create a new script called ‘Building’ and attach that to your buildings, edit the script with the following:

public BuildingType type = BuildingType.house;

This is a form of ‘Type Classification’ that allows you to give your buildings a type. You will also be able to access the type of a building with the . accessor, like so:

myBuilding.type = BuildingType.office;

Or:

if(myBuilding.type == BuildingType.skyscraper) {
    Debug.Log("This building is a skyscraper!");
}

Have a fiddle, good luck!

I believe u are looking for the c# typeof object.

http://msdn.microsoft.com/en-us/library/58918ffs(v=vs.71).aspx

ExtendsMyClass test = new ExtenedsMyClass();
Debug.Log( typeof(test) == MyClass );
Debug.Log( typeof(test) == ExtenedsMyClass);