so I have a class called InstalledObjects, and all objects like walls, door etc will inherit from this one. Now, I would like to instantiate a GameObject in a method, and ask in the method for a InstalledObject, that could be a Wall or a Door since they both inherit from InstalledObject.
My problem is that I can store in a variable a script.
First, this method is called
public void CreateBasicWall()
{
buildHandler.installedObject = new Wall();
}
That its stored here:
public InstalledObject installedObject;
And finally gets called here
BuildTile(t, buildModeTile);
And does that:
void Build(Tile tile, InstalledObject installedObject)
{
if(installedObject == null)
{
Debug.LogError("No se va a construir nada");
return;
}
GameObject go = new GameObject();
go.AddComponent<installedObject>();
}
Ignore the tile. It wont let me add the installedObject since is a var and not a type.
I remember that the class Wall inherits from InstalledObject, and I would like to have it as var so I can reuse code, but any other solution is appreciated.