This is my first attempt at scripting movement of an object in Unity. I’m working through the tutorials here: http://www.youtube.com/watch?v=rhpJPx8fICQ which seems to be a nice introduction to movement of objects.
I have an object that I’ve imported from blender. It is a bee and is a combination of multiple objects (i.e., a body, two eyes, and wings). I’ve added a Character Controller to the parent object named “bee”. I’ve also created a FirstPersonController script in C# following the aforementioned tutorial. I’ve added the FirstPersonController script to my “bee” object as well.
My reference to the CharacterController is returned as NULL as discovered by the following code:
Seems like it has something to do with the fact that I have multiple objects combined into a single parent object. I generated a simple cube in blender and a simple corridor. I put them into Unity and almost everything is working perfectly. Any pointers to figuring out how to appropriately apply a character controller and movement script to an object that is made up of multiple child objects?
The combined object using multiple objects to form the bee was causing problems with the movement. I’ll be doing some searching to figure out how to get this work; however, I was able to get a simple cube moving.
Have you tried creating an empty game object, and placing your bee mesh as the child of said object. From there you can simply place your components on the top level game object and it should take care of the issue.
This did, indeed, work. Will this cause any problems with referencing the bee object in the code later or with maintenance? I can’t forsee any reason that it would; however, I’m fairly new to building games using Unity.
If you’re needing to reference the actual mesh of the bee within one of the scripts on the top level object, I might suggest exposing a field to the inspector and handling the reference there. This way if the mesh changes further into development, you can just change the inspector field and be done with it, nothing in the script should need to be changed.