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

Capture and play voice with Asterisk ARI -

c++ - Can not find the "fiostream.h" file -

java - Why database contraints in HSQLDB are only checked during a commit when using transactions in Hibernate? -