- Home /
The question is answered, right answer was accepted
function overloading in Javascript
I need base functionality for a character, then extend a handful of the base functions for customizing certain characters. I'm trying to use classes and inheritance, but not getting something right. Here's relevant code:
SwapCharacter.js
#pragma strict
class SwapCharacter extends MonoBehaviour {
var TakeOverLight:GameObject;
virtual function Start()
{
TakeOverLight=GameObject.Find("TakeOverLight");
TakeOverLight.active=false;
}
}
**SwapCharacterExtended.js**
#pragma strict
class SwapCharacterExtended extends SwapCharacter{
}
`
This throws a NullReference on TakeOverLight.Active in Start(). It seems to me that Start is somehow called twice. The first instance kills the light, then on the second path, it's inactive and can't be found. Am I overloading the function properly? It runs fine if I delete the SwapCharacterExtends.js...
Answer by r67en · May 13, 2013 at 01:54 AM
Ok, stupid mistake. I had both files attached to the gameObject, so yes, everything was called twice. Didn't realize that only the inheriting file needed to be attached. Thanks.
Follow this Question
Related Questions
Inheritance best solution to handle *many* instances of a class with unique values? 1 Answer
Putting a Child Class into a List of Parent Type and then casting it back to a Child 0 Answers
How to set different classes at runtime 2 Answers
Inherited class, trying to overwrite variable. 0 Answers
The type 'myclass' does not have a visible constructor that matches the argument list 1 Answer