Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by MAILoW · May 25, 2016 at 01:07 AM · c#2dunity5game

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.. (^_^)

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

183 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges