Когда я ссылаюсь на плитки, они являются спрайтами в Unity с характеристиками.
Контекст: я пытаюсь добавить плитку (make с конструктором в классе Tile) в список.Переменная Tile в основном состоит из здоровья, спрайта, идентификатора и т. Д. Этого типа плитки.Все эти переменные внутри этого объекта Tile не равны Null и имеют какое-то значение.Моя проблема в том, что когда я запускаю наблюдение за переменными, когда они запускаются, они в общем случае равны нулю.Единственное, что я могу понять, почему это происходит, так это то, что переменная base в объекте Tile также имеет значение Null, но я понятия не имею, как решить эту проблему.
Это классназывается Tile
public int ID { get; set; }
public string Name { get; set; }
public Sprite Image { get; set; }
public int Durability { get; set; }
public bool Destructible { get; set; }
public static List<Tile> Tilelist; //Where I plan on storing all the tiles for later use
public Tile()
{
List<Tile> TileList = new List<Tile>();
}
public Tile(int id, string name, int durability, bool destructible, Sprite image)
: this()
{
ID = id;
Name = name;
Image = image;
Durability = durability;
Destructible = destructible;
}
Это класс TileAssign, в котором я создаю все плитки и их атрибуты, а затем добавляю их в список плиток класса
public Tile[] TileSprite(Tile[]Tiles)
{
int TilesNum = Tiles.Length;
for (int i = TilesNum - 1; i > 0; i--)
{
Tiles[i].Image = Resources.Load<Sprite>("TileSprites/" + Tiles[i].Name);
} //Running through my assets in Unity and finding sprites to match up with tile
return Tiles;
}
public void PopulateTiles()
{
Tile Unnamed = new Tile(0, "Unnamed", 0, false, null);
Tile SpaceStationFloor1 = new Tile(1, "SpaceStationFloor1", 50, true, null);
Tile SpaceStationWall1 = new Tile(2, "SpaceStationWall1", 100, true, null);
Tile Thrusters = new Tile(3, "Thrusters", 75, true, null);
Tile[] TilesInitialized = new Tile[] {
Unnamed,
SpaceStationFloor1,
SpaceStationWall1,
Thrusters
}; //Creating Tiles here ^^^^
//Plugging in my list to get corresponding sprites \/
TilesInitialized = TileSprite(TilesInitialized);
AddToList(TilesInitialized); //Sending list to fucntion to add them to tile's list
}
private static void AddToList(Tile[] TilesInitialized)
{
for (int i = TilesInitialized.Length - 1; i >= 0; i--)
{
Tile Newtile = TilesInitialized[i];
Tile.Tilelist.Add(Newtile); //Where I run into my issue
}
}
private void Start()
{
PopulateTiles();
Instantiate(Resources.Load("Tile1"), new Vector3(0f,0f,0f), Quaternion.identity);
}
![Look At bottom Left, the TilesInitialized Array and the individual Tile objects inside are their along with their characteristics and such, although a little explanation of what exactly the](https://i.stack.imgur.com/TovMa.png)