|
I am using inheritance (C#) with a base class that has
and I want my subclasses to be able to use temp, but whenever i try to use temp i get this error
But this works. But if I replace Debug.log with the base class object it errors.
(comments are locked)
|
|
You can use the generic version of GetComponent() instead, e.g.:
However, I don't think you can use Unity API functions such as Find() in field initializers or constructors (or at least you're not supposed to). Instead, you should perform initializations of that sort in Awake() or Start(). Not sure what you mean about the Debug.Log() part. Intersting. It worked, thank you. So inheritance in Unity is not like normal inheritance in C#? Because the base class var is not quite available to base classes, but can be accessed if I go through Get Component. I figure since if the var is in the base class, I should be able to access it in the subclasses. But, I must use GetComponent as this is how Unity handles inheritance?
Feb 17 '11 at 05:19 PM
RoR
Why are functions in the base class available to the sub-classes, but not variables?
Feb 17 '11 at 05:19 PM
RoR
I'm not completely clear on your question, but there shouldn't be anything particularly unusual about how inheritance in C# works with respect to Unity. In other words, the behaviour should be the same as in any other C# application (AFAIK, at least).
Feb 17 '11 at 08:31 PM
Jesse Anders
(comments are locked)
|
