Ok, so I have a javascript class that I wrote:
testClass.js:
class testClass
{
var health : float;
function doStuff()
{
Debug.Log("function called.");
}
}
Now when I try to add it to an empty game object, it says “Can’t add script behavior testClass. The script needs to derive from Monobehavior!”
So then I change it to this, and I can add it to the game object:
class testClass extends MonoBehavior
{
var health : float;
function doStuff()
{
Debug.Log("function called.");
}
}
Now I have another script attached to the game object to test the interaction of the class:
testReaderClass.js
function Start ()
{
var newTestClass : testClass = new testClass ();
newTestClass.health = 5;
print (newTestClass.health);
newTestClass.doStuff();
}
And I get the following warning message:
What does this mean? Could someone please shed some light on this?
ALSO: After I add the testClass.js to the game object, if I go back and delete “extends MonoBehavior” then I can have the class attached to the game object, and I get no warning message. Why is this?