- Home /
Question by
avi_75 · Apr 06, 2021 at 11:35 AM ·
guiunityeditorunityui
my ui score only works in editor but not in build version of the game
so initially my ui score and timer was working properly in the build and in the editor but after I followed a tutorial about mobile optimization since then the ui does does not work in build i do not thing it is a script problem because it was working before and when i was optimizing i did not touch the code at all mobile optimization tutorial : https://www.youtube.com/watch?v=ysk7ATmIeOs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
public static GameManager inst;
public Text timerText;
public float startTime;
PlayerDestroyer playerDestroyer;
public string seconds;
public int secondsInt;
public Image timeImage;
PlayerMovemnt playerMovemnt;
public Text speedText;
public Image speedImage;
public float t;
public string stSpeedText;
public string minutes;
string stLifeCount;
public Image warningImage;
public Text warningText;
string playerSpeedMultiplied;
public int multipliedSpeedAmount;
void Start()
{
startTime = Time.time;
playerDestroyer = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerDestroyer>();
playerMovemnt = GameObject.FindObjectOfType<PlayerMovemnt>();
}
// Update is called once per frame
void Update()
{
if (playerDestroyer.timerFinished == true)
return;
float t = Time.time - startTime;
minutes = ((int)t / 60).ToString();
seconds = (t % 60).ToString("f1");
timerText.text = minutes + ":" + seconds;
SpeedText();
WarningText();
}
private void Awake()
{
inst = this;
}
public void TimeStopColor()
{
timerText.color = Color.red;
speedText.color = Color.red;
}
public void ImageTimeColor()
{
timeImage.GetComponent<Image>().color = new Color(1, 0, 0.0173f, 0.2784f);
speedImage.GetComponent<Image>().color = new Color(1, 0, 0.0173f, 0.2784f);
warningImage.GetComponent<Image>().color = new Color(1, 0, 0.0173f, 0.2784f);
}
public void SpeedText()
{
playerSpeedMultiplied = (playerMovemnt.constantVelocity * multipliedSpeedAmount).ToString();//* multipliedSpeedAmount
stSpeedText = playerSpeedMultiplied;
speedText.text = $": { stSpeedText}";
}
public void WarningText()
{
stLifeCount = playerDestroyer.stWarning.ToString();
warningText.text = "X " + stLifeCount;
}
}
Comment
Your answer
Follow this Question
Related Questions
Editor Style permanently changed, how to change back? 2 Answers
Multi resolution GUI From 1920x1080 source to all lower resolutions (canvas scaler dead end) 0 Answers
How do I display a texture in the scene view? 1 Answer
Converting from EditorWindow to runnable window 1 Answer
Align text into PropertyField 1 Answer