Good day community )
I’m trying to create some sort of database. So I made 2 scripts.
1st is:
using System.Collections.Generic;
using UnityEngine;
public class Lists
{
public List<GameObject> gos;
public int qwty;
public int prefQwty;
public string[] prefPath;
public GameObject goFather;
public Vector3 pos;
public Lists(){}
}
And the 2nd one is:
using System.Collections.Generic;
using UnityEngine;
public class Adder
{
public int goQwty = 2;
public void Add()
{
Lists[] toCreate = new Lists[goQwty];
Debug.Log(toCreate);
toCreate[0].gos = new List<GameObject>();
toCreate[0].qwty = 10;
toCreate[0].prefQwty = toCreate[0].gos.Count;
toCreate[0].prefPath[0] = "/Stuff/Bullets/Bullet";
toCreate[0].goFather = GameObject.FindGameObjectWithTag("Player").transform.GetChild(0).gameObject;
toCreate[0].pos = new Vector3(.5f, 0, 0);
toCreate[1].gos = new List<GameObject>();
toCreate[1].qwty = 10;
toCreate[1].prefQwty = toCreate[0].gos.Count;
toCreate[1].prefPath[0] = "/Chars/Enemies/Red";
toCreate[1].goFather = GameMaster.Instance.enemies;
toCreate[1].pos = Vector3.zero;
}
}
But when I’m trying to “create” something using this database, it’s always gives me this annoying “Object reference not set to an instance of an object” (
Can U tell me, what am I doing wrong pls)))
What line is giving you this error? It seems a GameObject or variable was not set: either in the inspector or the code, provided you can give us what line the error is on…
I even tried to make this with List<> instead of Array
First script:
public class Lists
{
public List<GameObject> gos;
public int qwty;
public string[] prefPath;
public int prefQwty;
public GameObject goFather;
public Vector3 pos;
public Lists(List<GameObject> Gos, int Qwty, string[] PrefPath, int PrefQwty, GameObject GoFather, Vector3 Pos)
{
Gos = gos;
Qwty = qwty;
PrefPath = prefPath;
PrefQwty = prefQwty;
GoFather = goFather;
Pos = pos;
}
}
And the second:
public class Adder
{
public int goQwty = 2;
public void Add()
{
List<Lists> toCreate = new List<Lists>();
//Bullets
toCreate.Add(new Lists(new List<GameObject>(), 10, new string[1] { "/Stuff/Bullets/Bullet" }, 1, GameObject.FindGameObjectWithTag("Player").transform.GetChild(0).gameObject, new Vector3(.5f, 0, 0)));
//Enemys
toCreate.Add(new Lists(new List<GameObject>(), 10, new string[1] { "/Chars/Enemies/Red" }, 1, GameMaster.Instance.enemies, new Vector3(0, 0, 0)));
for (int i = 0; i < toCreate.Count; i++)
{
Pooler.Instance.Create(toCreate<em>.gos, toCreate<em>.qwty, toCreate<em>.prefPath, toCreate<em>.prefQwty, toCreate_.goFather, toCreate*.pos);*_</em></em></em></em>