|
I have two scripts on an object. One references the other: The other script is C# monobehavior, this one is JS. The c# script is in the Plugins folder. The component IS there on the gameobject. Even so, I put a 'require' of that component in the script just in case. For some reason, I'm getting back null for this. I also tried GetComponent("OtherCS") and gameObject.GetComponent(.....) but nothing seems to work. Very strange. I restarted, rebooted, same anomoly. I'm getting no errors on script compile, and I've reimported the scripts without problem too. I have the 'other' script on another game object where it works just fine. Anyone got any ideas what might cause this?
(comments are locked)
|
|
This didn't answer my question but did solve my problem: I disinherited it from MonoBehavior to make it a normal class and just new OtherCS() it.
(comments are locked)
|

The answer is not in what you have posted. I just tested exactly that and it works fine. The only way I could get it to fail like you did was for OtherCS to inherit from MonoBehaviour, add the script, then remove that inheritance. I was surprised Unity gave no error.
Nothing to do with compilation order? Try to place the JS script in a new folder in Assets - it will compile last, and maybe it can "see" the CS script. I know, you should have compiler errors if OtherCS was unknown when the JS script was compiled, but it wouldn't be the first time Unity "swallowed" errors during compile time to spit them at runtime...
@aldonaletto: he's already ensured the order by placing
OtherCSin the Plugins folder.