private unsafe void ImportLights(int nlight) { // allocate array objects = new GameObject[nlight]; // process objects for (int i = 0; i < nlight; i++) { // get object name StringBuilder name = new StringBuilder(100); MJP.GetElementName(MJP.TElement.LIGHT, i, name, 100); if (name.Length == 0) { name.Append("Light "); name.Append(i); } // create new GameObject, place under root objects[i] = new GameObject(name.ToString()); Light lightComp = objects[i].AddComponent <Light>(); objects[i].transform.parent = root.transform; // get MuJoCo object descriptor MJP.TLight obj; MJP.GetLight(i, &obj); //GetLightState // set mesh lightComp.type = obj.directional != 0 ? LightType.Directional : LightType.Point; lightComp.shadows = obj.castshadow == 0 ? LightShadows.None : LightShadows.Soft; lightComp.color = new Color(obj.diffuse[0], obj.diffuse[1], obj.diffuse[2]); lightComp.range = (float)Math.Sqrt(255 / obj.attenuation[2]); float[] pos = { 0, 0, 0 }; float[] dir = { 0, 0, 0 }; fixed(float *ppos = pos) fixed(float *pdir = dir) MJP.GetLightState(i, 0, ppos, pdir); objects[i].transform.localPosition = new Vector3(-pos[0], pos[2], -pos[1]); objects[i].transform.rotation = Quaternion.LookRotation(new Vector3(-dir[0], dir[2], -dir[1]), Vector3.up); } }