Hello All,
I have a peculiar error. I hope I can’t just chalk it up to the “I’m doing it wrong” category, but you never know.
I have imported a scene that a co-worker and I have been working on. On his computer, everything runs perfectly. I have imported his scene with all of his scripts dependencies and prefabs. The scene is extremely simple with just a single first person controller. I am trying to lock the mouse in a first person controller. We are handling this by disabling the MousLook script. In the project that the controller was built in, the code works perfectly. However, In my project, I receive an error message when calling the following:
GameObject.Find("Main Camera").GetComponent("MouseLook").enabled = true;
GameObject.Find("Main Camera").GetComponent("Raycasting").enabled = false;
this generates the following error. Note there is only a single Main Camera on the screen and the same GameObject.Find call below works perfectly to disable the Raycasting script.
NullReferenceException: Object reference not set to an instance of an object
Boo.Lang.Runtime.RuntimeServices.Dispatch (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, System.Object[] args, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.Dispatch (System.Object target, System.String cacheKeyName, System.Object[] args, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.SetProperty (System.Object target, System.String name, System.Object value)
TrashShooterController.Update () (at Assets/Scripts/ControlScripts/TrashShooterController.js:43)
However, when I use the ml2, which i linked by dragging and dropping the script from the inspector, I get no error. The example of the code is:
var ml2: MouseLook; //a mouselook script linked to the main camera
ml2.enabled = false;
//GameObject.Find("Main Camera").GetComponent("MouseLook").enabled = true;
GameObject.Find("Main Camera").GetComponent("Raycasting").enabled = false;
Am I missing some kind of dependency that was not exported? Or is this a type of bug? I have got the controller to work just the way I want with the ml2 link, but I just wanted to know if I was missing something for future reference should this error occur again.