how to make the sprite invinsible and reappear and how to call the sprite data from another script
Hi everyone. I need some help on my project. can you guys help me. I follow the tutorial of the 2048 puzzle and my problem is when the tutorial need to reset the gamefield at the beginning of the game. I had no knowledge in the disappearing and reappearing the sprites and also in the passing of the sprite data from the tileStyle Script to Tiles script.. i am currently doing my own version of 2048 puzzle I want it to be shapes instead of numbers.. these are my codes..
public class Tiles : MonoBehaviour
{
// these there from another script
public bool mergeThisTurn = false;
public int indRow;
public int indCol;
public int Number
{
get
{
return number;
}
set
{
number = value;
if (number == 0)
{
SetEmpty();
// setDeactive();
}
else
{
ApplyStyle(number);
SetVisible();
// setActive();
}
}
}
private Text NO;
private int number;
private Image Tileimage;
private Animator anim;
public GameObject go;
void Awake()
{
go = new GameObject ();
go.AddComponent<SpriteRenderer> ();
anim = GetComponent<Animator> ();
NO = GetComponentInChildren<Text>();
Tileimage = transform.Find ("numberedCell").GetComponent<Image> ();
}
// play animation
public void playMergeAnimation()
{
anim.SetTrigger ("Merge");
}
public void playAppearAnimation()
{
anim.SetTrigger ("Appear");
}
//apply each of the tile with the tilestyle.
void ApplyTileStyle (int index)
{
go.GetComponent<SpriteRenderer> ().sprite = TileStyle.Instance.Tilestyles [index].seperite;
NO.text= TileStyle.Instance.Tilestyles[index].mark.ToString();
Tileimage.color = TileStyle.Instance.Tilestyles [index].tileColor;
}
void ApplyStyle(int num)
{
switch(num)
{
case 2:
ApplyTileStyle(0);
break;
case 4:
ApplyTileStyle(1);
break;
case 8:
ApplyTileStyle(2);
break;
case 16:
ApplyTileStyle(3);
break;
case 32:
ApplyTileStyle(4);
break;
case 64:
ApplyTileStyle(5);
break;
case 128:
ApplyTileStyle(6);
break;
case 256:
ApplyTileStyle(7);
break;
case 512:
ApplyTileStyle(8);
break;
case 1024:
ApplyTileStyle(9);
break;
case 2048:
ApplyTileStyle(10);
break;
case 4096:
ApplyTileStyle(11);
break;
case 8192:
ApplyTileStyle(12);
break;
case 16384:
ApplyTileStyle(13);
break;
case 32768:
ApplyTileStyle(14);
break;
default:
Debug.Log("please check the numbers");
break;
}
}
// to set the visibility of the tiles.
private void SetVisible()
{
Tileimage.enabled = true;
NO.enabled = true;
go.SetActive (true);
}
private void SetEmpty()
{
Tileimage.enabled = false;
NO.enabled = false;
go.SetActive (false);
}
}
and this is the TileStyle Script
public class tileStyle
{
// these will appear in the inspector
// input the style of the tiles.
public int mark;
public Sprite seperite;
public Color32 tileColor;
}
public class TileStyle : MonoBehaviour {
//singleton
public static TileStyle Instance;
public tileStyle[] Tilestyles;
void Awake()
{
Instance = this;
}
}
i am sorry about the bad english and thank you in advance.. (^_^)
Your answer
Follow this Question
Related Questions
Scale of object does not update properly with public variable 1 Answer
[2D] Getting the y coordinate of the top of a game object 0 Answers
Load Scene Unity by Application.LoadLevelAsync 0 Answers
How to check if player is rapidly rotating the joystick? 2 Answers
C# 2D Top down game how to detect if objects are touching while they can pass through each other? 1 Answer