unity3d - Null reference exception after instantiating a light gameobject -


i coded class, declare light attribute. in constructor instantiate light object before using it, got null reference exception @ line after instantiation (nodelight.type = lighttype.spot;).

 using unityengine;  using system.collections;   public class node{       public bool walkable;      public vector3 worldposition;      public bool selected;      public light nodelight;       public node(bool _walkable, vector3 _worldpos) {          selected = false;          walkable = _walkable;          worldposition = _worldpos;          nodelight = new light();          nodelight.type = lighttype.spot;          nodelight.transform.position = new vector3(worldposition.x, worldposition.y + 3f, worldposition.z);          nodelight.enabled = false;      }  } 

thank help

a light component, should exist within gameobject.

have @ example unity docs:

public class exampleclass : monobehaviour {     void start() {         gameobject lightgameobject = new gameobject("the light");         light lightcomp = lightgameobject.addcomponent<light>();         lightcomp.color = color.blue;         lightgameobject.transform.position = new vector3(0, 5, 0);     } } 

try approach, or try adding nodelight component of gameobject, , changing position, rather individual light component's.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -