Hi, Im stuck on changing a variable in a JS script from a CS Script. Can I change the variable directly or do I call a function in the JS script from the CS script?
The cs script I am trying:
I keep getting a NullReferenceException : Object reference not set to an instance of an object. This is for the getComponent call. the GameObject.Find works ok and I get Main Camera back. Is this even possible?
K this works:
It doesn't matter what language the scripts are written in, a public member variable is a public member variable.
The trick is that you have to be using the right type. So your commented out GetComponent is the correct one.
The non-commented-out GetComponent is getting the component on your SceneControl object and not your Camera object. That's probably why you're geting a null reference exception. Also if you wanted to use the non-generic GetComponent you'll have to cast your return type to the type you want to access. Component doesn't have a "target" variable.
Edit: this may not be entirely accurate. http://unity3d.com/support/documentation/ScriptReference/index.Script_compilation_28Advanced29.html