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 /
avatar image
1
Question by ruchit4601 · Dec 26, 2018 at 10:51 PM · unity 5textcanvas

How to create a blinking text and disabling it when the user clicks on the screen.,what would be the code to display a blinking text "TAP TO PLAY" and make it disable when the user touches the screen.

I am almost done with my game but the last thing I need is a blinking text "TAP TO PLAY" which can be disabled when the user clicks on the screen.,I am almost done with my game but I need to add a TAP TO PLAY blinking text which can be disabled when the user taps is the screen.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Otavio_ · Dec 28, 2018 at 07:23 PM

There is a much easier way, i'll explain quickly:

  • create a button, and write you text there and set the image transparency to 0;

  • in "On click" function of the button in inspector, you put the same button and select GameObject > SetActive and un-check the box;

  • then, all you have to do is an animation that keep changing the transparency of the text from 0 to 255

Comment
Add comment · Show 2 · Share
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
avatar image ruchit4601 · Dec 28, 2018 at 07:50 PM 0
Share

how should I set the transparency to 0?

avatar image Otavio_ ruchit4601 · Jan 07, 2019 at 12:14 AM 0
Share

click in the button > inspector > image (script) > color > A = 0

avatar image
1

Answer by 3kWikiGames · Dec 26, 2018 at 10:57 PM

There's several ways you could do this, if you want the text to completely disappear during blinking then you could either create an animation that loops on and off until the player clicks which may be much simpler than writing a code with a timer, then create a method that turns the sprite renderer on and off between certain intervals based on the timer. EDIT: I've also included the edited code for easier viewing below.

 public class TapToPlay : MonoBehaviour {
       public float timer;
       public GameObject Tap;
       public static bool activated = false;
  
       void exit()
       {
           if (Input.touchCount > 0 && activated == false)
           {
             Tap.SetActive(false);
             activated = true;
           }
       
   
           }
   
       void Update()
       {
           exit();
           timer = timer + Time.deltaTime;
           if(timer >= 0.5)
           {
                   GetComponent<Text>().enabled = true;
           }
           if(timer >= 1)
           {
                   GetComponent<Text>().enabled = false;
                   timer = 0;
           }
   
       }
   
   }
Comment
Add comment · Show 6 · Share
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
avatar image ruchit4601 · Dec 26, 2018 at 11:05 PM 0
Share

Actually I figured out thee Blinking part but the thing is that I don't know how should I disable the text when the user clicks the screen. It's basically like TAP TO PLAY (constant blinking) when user clicks the screen i.e (Input.Get$$anonymous$$ouseButtonDown(0)) the text (TAP TO PLAY ) should not be shown.

avatar image 3kWikiGames ruchit4601 · Dec 27, 2018 at 03:35 AM 0
Share

I guess if you had to you could add a bool at the top and so have it like:

 private bool activated = false;
 
 if(input.Get$$anonymous$$ouseButtonDown(0)){
    if(activated == false){
       text.SetActive(false) //or whatever else you would need to do
       activated = true;
 }

That would allow you to reactivate the text when you need to, but also leave it unavailable in case you don't. Not sure if that's exactly what you're looking for but let me know.

avatar image ruchit4601 · Dec 27, 2018 at 09:52 PM 0
Share
 public class TapToPlay : $$anonymous$$onoBehaviour {
     public float timer;
     public GameObject Tap;
     void exit()
     {
         if (Input.touchCount > 0)
         {
           Tap.SetActive(false);
         }
     
 
         }
 
     void Update()
     {
         timer = timer + Time.deltaTime;
         if(timer >= 0.5)
         {
                 GetComponent<Text>().enabled = true;
         }
         if(timer >= 1)
         {
                 GetComponent<Text>().enabled = false;
                 timer = 0;
         }
 
     }
 
 }


This is the code that I used it successfully blinks tap to play . But it doesn't go away when the game starts (when there is a touch input).

avatar image 3kWikiGames ruchit4601 · Dec 28, 2018 at 05:45 PM 0
Share

Try this and see if that works, may not be a very advanced way of coding it but it should work. To reactivate the blinking text in any other script just write TapToPlay.activated = false; Tap.SetActive(true) and set the touch count back to 0.

    public class TapToPlay : $$anonymous$$onoBehaviour {
      public float timer;
      public GameObject Tap;
      public static bool activated = false;
 
      void exit()
      {
          if (Input.touchCount > 0 && activated == false)
          {
            Tap.SetActive(false);
            activated = true;
          }
      
  
          }
  
      void Update()
      {
          exit();
          timer = timer + Time.deltaTime;
          if(timer >= 0.5)
          {
                  GetComponent<Text>().enabled = true;
          }
          if(timer >= 1)
          {
                  GetComponent<Text>().enabled = false;
                  timer = 0;
          }
  
      }
  
  }


avatar image ruchit4601 · Dec 28, 2018 at 06:46 PM 0
Share

Tried that code but still doesn't work the text doesn't stop displaying after the input.

avatar image 3kWikiGames ruchit4601 · Jan 02, 2019 at 06:08 PM 0
Share

$$anonymous$$ake sure you have the exit() method within the update, otherwise it wont activate it unless you're activating it with a button. If that's the case you would need to make exit a public void method.

avatar image
0

Answer by upasnavig90 · Dec 27, 2018 at 06:00 AM

For blinking the text you can also play with alpha of the color in text, or changing color in animation whatever you want.

and if "Tap to play" is ui button then you can use onbuttonclick event. and simply disable the text or i will suggest to make it interactable false instead of disabling. just a suggestion. :)

and if "Tap to play" is not a ui button than go with the code suggested by @3kWikiGames

Thanks

Comment
Add comment · Share
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

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

197 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 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

My code will not change Canvas Text at all [No errors] 3 Answers

Best way to show image with text next to image target in Unity 0 Answers

Unity UI Text with markup tags - “String too long for TextMeshGenerator” 0 Answers

How to instantiate a prefab between Canvas and a Button? 0 Answers

How to attach a canvas to a game object properly? 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