I create a class inherited another class based monobehavior
“ItemBase.js” File
class ItemBase extends Monobehavior {
var toOpp : boolean;
var curCamera : Tranform;
function Start() {
if(curCamera == null)
Debug.Log(“curCamera is null!!!”);
}
}
“Item.js” File
class Item extends ItemBase {
var nameStr : String;
}
Drag the Item.js to one GameObject in hierarchy
in the inspector , show the three variable(toOpp, curCamera and nameStr)
drag the camera in hierarchy to curCamera
running and the console output is:
curCamera is null!!!
why! why! why!
I just tried your code (after fixing the spelling mistakes) and it works fine. Heres what I used:
Base.js
class Base extends MonoBehaviour {
var toOpp : boolean;
var curCamera : Transform;
function Start() {
if(curCamera == null) {
Debug.Log("curCamera is null!!!");
} else {
Debug.Log("Has curCamera");
}
}
}
Child.js
class Child extends Base {
var nameStr : String;
}
oh my god , i find my mistake
item.js file is completed yesterday and have been draged to one temporary gameObject
now, this file was attached to two gameObjects, i forget.
the mistake command output is from another Item instance
thanks Dman