Hello thank you for reading. I am following a 2048 tutorial and he is using text/color for his tiles. I am using an image.
His code is as follows when applying different styles to the tiles:
TileText.text = TileStyleHolder.Instance.TileStyles [index].Number;
TileText.color = TileStyleHolder.Instance.TileStyles[index].TextColor;
TileImage.color = TileStyleHolder.Instance.TileStyles [index].Tilecolor;
My style holder code is as follows:
[System.Serializable]
public class TileStyle
{
public Sprite tile_number;
}
public class TileStyleHolder : MonoBehaviour
{
//SINGLETON
public static TileStyleHolder Instance;
public TileStyle[] TileStyles;
void Awake()
{
Instance = this;
}
}
my Tile code is as follows:
public class Tile : MonoBehaviour
{
public bool mergedThisTurn = false;
public int indRow;
public int indCol;
public int Number
{
get
{
return number;
}
set
{
number = value;
if (number == 0)
SetEmpty();
else
{
ApplyStyle(number);
SetVisible();
}
}
}
//private SpriteRenderer spriteRenderer;
private Sprite tile_number;
private int number;
void Awake()
{
Sprite tile_number = GetComponentInChildren<Image>.sprite ();
}
void ApplyStyleFromHolder(int index)
{
tile_number.image = TileStyleHolder.Instance.TileStyles[index].tile_number;
}
And it throws the error:
'Sprite' does not contain a definition for 'image' and no accessible extension method
However, if i use this line of code:
tile_number = TileStyleHolder.Instance.TileStyles[index].tile_number;
Then it doesn't throw an error, but it also doesn't change the tile style from 2 to 4 once merged. It stays as a 2, and does not throw an error.
Please help, I do now know how to convert the image to the next image in the array.