Storing positions and booleans together
I need to make a list of elements with properties x, y and isMine where x and y are integers and isMine is a boolean value. How should I make this list? I need to know how to:
Access the values of each individual element on the list
Be able to change the values of each property
If you could tell me how to do those two things with whatever method you suggest , I will appreciate it (bonus points for examples)! Cheers!
Comment
Best Answer
Answer by Arkaid · Jul 20, 2016 at 05:31 AM
Just make a list of objects with the properties you need?
The class could be something like:
public class Item
{
public int x;
public int y;
public bool isMine;
}
and then your list:
List<Item> itemList = new List<Item>();
1) Access the values of each individual element on the list
foreach (Item item in itemList)
{
// do stuff with item
Debug.Log(string.Format("({0},{1}) -> {2}", item.x, item.y, item.isMine));
}
2) Be able to change the values of each property (example, change the bool value of Item with x = 3 and y = 2)
Item item = itemList.Find(i => i.x == 3 && i.y == 2);
item.isMine = true;