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 ZeroFaction · Mar 02, 2016 at 12:32 PM · androidtextimagecolor.lerpfading problem

Text and Image fill lerp issues - Android

I have a game that uses a lerp to fade text in and out by modifying the color of the text alpha channel on the title screen. This is used to pulse "Touch Screen" in and out on the screen. The code works perfectly on PC but when it is ported to Android the color lerping ceases to function.

On Android the color of the text stays completely white and does not fade to clear. The interesting thing is that the lerp functions properly if the player touches and holds the screen. But it does not function without the player touching the screen (which it is suppose to do).

The text is supposed to fade from white to clear then back to white while waiting for the player to touch the screen. After the screen is touched, another text object is supposed to fade from clear to white displaying some additional information.

Here is the code controlling the fade.

 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.SceneManagement;
 
 public class TitleScreenManager : MonoBehaviour {
     [SerializeField] Text title, prompt = null, wDay = null, credits = null;
     [SerializeField] Animator clockAnim;
     [SerializeField] AudioSource sfx;
     [SerializeField] AudioClip alarm;
     private float blinkTimer = 3f, blinkStartTime = 0f;
     private bool playing = false, fadeUp = true, gameStarted = false;
     private int workDay = 25;
 
 
     // Use this for initialization
     void Start () {
 #if UNITY_STANDALONE
         prompt.text = "Just Press Spacebar";
 #elif UNITY_ANDROID
         prompt.text = "Touch Screen";
 #endif
         blinkStartTime = Time.time;
         //PlayerPrefs.DeleteAll ();
         if (!PlayerPrefs.HasKey ("WSRworkDay")) {
             PlayerPrefs.SetInt ("WSRworkDay", 1);
             wDay.text = "DAY 1";
         } else {
             workDay = PlayerPrefs.GetInt ("WSRworkDay");
             wDay.text = "DAY " + workDay;
         }
     }
     
     // Update is called once per frame
     void Update () {
         if (Input.GetKeyDown (KeyCode.Escape)) {
             Application.Quit ();
         }
 #if UNITY_STANDALONE 
         if (Input.GetKeyDown (KeyCode.Space) && !playing) {
             playing = true;
             prompt.color = Color.clear;
             clockAnim.SetTrigger ("startGame");
             blinkStartTime = Time.time;
             sfx.loop = true;
             sfx.clip = alarm;
             sfx.Play ();
         }
 #elif UNITY_ANDROID
         if(Input.GetTouch (0).phase == TouchPhase.Began && !playing){
             playing = true;
             prompt.color = Color.clear;
             clockAnim.SetTrigger ("startGame");
             blinkStartTime = Time.time;
             sfx.loop = true;
             sfx.clip = alarm;
             sfx.Play ();
         }
 #endif
         if (!playing) {
             FadeText ();
         } else {
             if(!gameStarted){
                 StartGame ();
             }
         }
     }
 
     void FadeText(){
         float fadeFrac = (Time.time - blinkStartTime) / blinkTimer;
         Color fadeColor = (fadeUp) ? Color.Lerp (Color.clear, Color.white, fadeFrac) : Color.Lerp (Color.white, Color.clear, fadeFrac);
         prompt.color = fadeColor;
         if (fadeFrac >= 1f) {
             fadeUp = !fadeUp;
             blinkStartTime = Time.time;
         }
     }
 
     void StartGame(){
         float fadeFrac = (Time.time - blinkStartTime) / blinkTimer;
         Color titleFadeColor = Color.Lerp (Color.white, Color.clear, fadeFrac);
         Color creditFadeColor = Color.Lerp (Color.white, Color.clear, fadeFrac);
         Color dayFadeColor = Color.Lerp (Color.clear, Color.white, fadeFrac);
         title.color = titleFadeColor;
         credits.color = creditFadeColor;
         wDay.color = dayFadeColor;
         if (fadeFrac >= 1f && clockAnim.GetCurrentAnimatorStateInfo (0).IsName ("Clock Blink In Game")) {
             gameStarted = true;
             SceneManager.LoadScene ("Game Scene");
         }
     }

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Code-generated ui text disappear when installed on android device 0 Answers

Why does WebGL scrollable text area display badly, but works fine standalone? 0 Answers

Black UI when building to android 1 Answer

How do I make both an Image and Text appear when a button is clicked? 0 Answers

How to make a text and image appear for few seconds if you pick up a gameobject? 0 Answers


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