Search Unity

Trouble With Inheritance

Discussion in 'Editor & General Support' started by Phenomonaut, Jan 6, 2016.

  1. Phenomonaut

    Phenomonaut

    Joined:
    Sep 30, 2012
    Posts:
    61
    Working with inheritance for the first time and having trouble accessing variables from a base class. I have a script/class called BaseDriver. In another script, I just need to change the name of the class from
    Code (csharp):
    1. public class DerivedDriver : MonoBehaviour {}

    to
    Code (csharp):
    1. public class DerivedDriver : BaseDriver {}

    and DerivedDriver should inherit the properties of BaseDriver, correct?

    When I try this I get the error that "the type or namespace BaseDriver could not be found..." How can I connect these classes?
     
  2. Sebioff

    Sebioff

    Joined:
    Dec 22, 2013
    Posts:
    218
    If you want to inherit from BaseDriver you also need that BaseDriver class somewhere (usually in it's own file).
    So what you're missing is:

    Code (CSharp):
    1. public class BaseDriver : MonoBehaviour {}
    (In your post you say you have that, but the compiler error says otherwise)