2D Toolkit Forum
2D Toolkit => Support => Topic started by: djip123 on October 31, 2013, 10:49:08 am
-
Hey. I got some code that i think is right, but it gives a error: NullReferenceException: Object reference is not set to an instance of an object.
I have dragged the Datacollection into the script. But i guess there could be a issue there ?
public tk2dSpriteCollectionData CD;
public int i;
public List<GameObject> Servers = new List<GameObject>();
private RoomInfo[] oldList;
void Awake () {
}
// Update is called once per frame
void Update () {
if (oldList != PhotonNetwork.GetRoomList()){
// foreach(tk2dSprite obj in this.gameObject.GetComponentsInChildren<tk2dSprite>()){
// GameObject.Destroy(obj.gameObject);
// }
i = 0;
foreach (RoomInfo game in PhotonNetwork.GetRoomList()){
int spriteID = CD.GetSpriteIdByName("infoBox");
// GameObject tempObj = new GameObject("Server "+i.ToString());
GameObject obj = new GameObject();
tk2dSprite.AddComponent(obj, CD, spriteID);
// tk2dSprite tempSpr = tempObj.AddComponent<tk2dSprite>();
// tempSpr.SetSprite(CD,CD.);
// tempObj.GetComponent<tk2dSprite>().SetSprite
// tempObj.transform.position = new Vector3(0,0,-0.1f);
// this.gameObject.AddChild(tempObj.transform);
//Servers.Add(tempObj);
i++;
Debug.Log("Server Added");
}
oldList = PhotonNetwork.GetRoomList();
Debug.Log("GameList Updated");
}
}
Please check if something is wrong ?
-
Which line is triggering the error?
And what are CD and spriteID? Can you debug.log them?
-
This line gives Error:
int spriteID = CD.GetSpriteIdByName("infoBox");
And CD returns null, but i don't really understand since i have dragged it in the script, and it seems ok.
-
I'm not sure why CD would be null, have you tried debugging this?
-
Wow, so sad, the script was attached to another Gameobject on the scene! Ok my bad ^_^
But anyway thanks for the fast reply, maybe i will need it later, keep up the good work with 2D ToolKit!