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");
}
}
Your answer
Follow this Question
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