public List<Achievment> Achievments = new List<Achievment>();
[System.Serializable]
public class Achievment
{
public string Name;
public string Description;
public string Img;
public int Xp;
public int Credits;
public string Board;
public string Deck;
public string Require;
public int Count;
public bool Completed;
public Achievment(string nam, string des, string img, int xp, int cre, string boa, string dec, string req, int cou, bool com)
{
Name = nam;
Description = des;
Img = img;
Xp = xp;
Credits = cre;
Board = boa;
Deck = dec;
Require = req;
Count = cou;
Completed = com;
}
}
and am trying to add item into the sublist by using
i have an empty list called Achievments and with that list i have a SubList called Achiement.
currently the lists are empty and im trying to add into the achivmenst list an achievment. - Achievments.Add(new Achievment(“”,“”,“”,0,0,“”,“”,“”,0,false)
So basically the list effectively is null which why im trying to add to it.
so what am i missing when you say check every object??
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class AchievmentsManager : MonoBehaviour {
public static AchievmentsManager Instance;
//list of achievments
public List<Achievment> Achievments = new List<Achievment>();
// Use this for initialization
void Start ()
{
Instance = this;
}
// Update is called once per frame
void Update ()
{
}
}
[System.Serializable]
public class Achievment
{
public string Name;
public string Description;
public string Img;
public int Xp;
public int Credits;
public string Board;
public string Deck;
public string Require;
public int Count;
public bool Completed;
public Achievment(string nam, string des, string img, int xp, int cre, string boa, string dec, string req, int cou, bool com)
{
Name = nam;
Description = des;
Img = img;
Xp = xp;
Credits = cre;
Board = boa;
Deck = dec;
Require = req;
Count = cou;
Completed = com;
}
}
so …
AchievmentsManager.Instance = the script
AchievementsManager.Instance.Achievments = the empty list
so how do i check a script is empty or null and an empty list is empty or null???
im sorry but i am totally missing the point here so let me re-ask the question
How do i add an achievment into the achievments list in c# script.
Ok i now have a new problem which is how do add too, access a list within a list.
i have searched all over the net but cant find the right syntax that works.
my code is -
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class BoardManager : MonoBehaviour {
public static BoardManager Instance;
//list of boards owned by player
public List<Boards> OwnedBoards = new List<Boards>();
//board chosen for current game
public Boards CurBoard;
void Awake ()
{
Instance = this;
}
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
}
}
[System.Serializable]
public class Boards
{
public string Name;
public string Description;
public Enviroments Enviroment;
public string Img;
public GameObject Prefab;
public bool Night;
public List<BackGroundScene> BackGround = new List<BackGroundScene>(); // list of player
public List<Cells> cell = new List<Cells>();
public enum Enviroments
{
DenseFog,
Raining,
Stromy,
Cloudy,
Sunshine
}
public Boards(string nam, string des, string img, bool nig)
{
Name = nam;
Description = des;
Img = img;
Night = nig;
}
}
[System.Serializable]
public class Cells
{
public string color;
public CellType cellType;
public bool Trapped;
public string trappedByPlayerName;
public int Card;
public enum CellType
{
none,
drawcard,
special,
events
}
public Cells(string col)
{
color = col;
}
}
[System.Serializable]
public class BackGroundScene
{
public string Name;
public bool IsLimbo;
public GameObject ScenebackGround;
}
that was my 1st thought but i don’t get cell or cells and i get the error as i type out the line which is what i would expect.
error CS1061: Type System.Collections.Generic.List<Boards>' does not contain a definition for cell’ and no extension method cell' of type System.Collections.Generic.List’ could be found (are you missing a using directive or an assembly reference?)
so im stuck trying to work out how i actually access the list within a list
i have intergers in an xml to store the enum and am using
CellTypes CellType = (CellTypes)ctype;
the interger is passed ok but the enum is not getting chosen.
this is the associated code.
[System.Serializable]
public class Cells
{
public string color;
public CellTypes CellType;
public bool Trapped;
public string trappedByPlayerName;
public int Card;
public enum CellTypes
{
none = 0,
drawcard = 1,
special = 2,
events = 3
}
public Cells(string col, int ctype)
{
color = col;
CellTypes CellType = (CellTypes)ctype;
//CellTypes CellType = (CellTypes)Enum.Parse(typeof(CellTypes), ctype);
Debug.Log(ctype);
}
}
sorry to ask so many questions but this area of my code is giving me major hassle.