Subclassing no-go? (C#)

Hi :)

I'm creating a game which will have many forms of the same object, with many different functionalities.

I am trying to create a skeleton class which contains all of the shared properties of these objects. Then, I define it as the superclass to all the other objects.

That works fine and well, until... Anonymous typing.

Say I have the class BaseClass.

Then I have the class SubClass, which is a subclass of BaseClass

Finally, I have TestClass, which contains one variable of type BaseClass.

If I add BaseClass to a new gameobject, and try to add the gameobject to the variable in TestClass, it works fine.

But if I instead add SubClass, it does not work at all! It simply will not attribute its self to the variable!

How in blazes can I get this to work??

3 classes:

BaseClass:

using UnityEngine;
using System.Collections;

public class BaseClass : MonoBehaviour
{
    public string mytext;
    public int countA = 0;
    void Update ()
    {
        IC();
    }

    public void IC()
    {
        countA++;
    }
}

SubClass:

using UnityEngine;
using System.Collections;

public class SubClass : BaseClass
{
}

TestClass:

public class TestClass : MonoBehaviour {
    public BaseClass bc;
}

Your code seems ok, and I use subclassing all the time without issues.

The only thing that comes to my mind, is that maybe you're storing bc "as SubClass", instead than "as BaseClass", and thus the type don't match.

If not, could you post the method you use to store/instantiate bc?