- Home /
Question by
MihajloNen · Mar 12, 2016 at 05:52 PM ·
uieditorandroid buildbuttons
Android build does not show UI buttons after SetActive
I am working on a project where multiple questions have to be answered by choosing a option(Text on Button). 1st Question(2 option-UI buttons) are SetActive(true). Then 2nd question the Buttons go SetActive(false) and then they should appear at the 3rd question again. Sometimes SetActive did not work well and I used the CanvasGroup-component and set *kursiv*intractable=false and *kursiv*alpha=0. In the Editor it all works well to the point I worked with Unity 5.1. After I updated to 5.3.3 the Buttons at question 3 do not show up after entering the anwer in the Inputfield. BUT ONLY IN ANDROID BUILD! in the editor inside unity it all works fine. Hope someone can help me quickly. TY
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class HideShowButtons : MonoBehaviour {
public bool showNachthimmel = false;
public float fadeWartezeit;
public GameObject Button_Erde;
public GameObject Button_Alter;
public GameObject Button_E_Text;
public GameObject Button_A_Text;
public GameObject Inputfield_Frage;
public GameObject Nachthimmel;
private bool Inputfiel_SetActiveFalse = false;
//private bool hideButton = true;
public float ZeitBisButtonSHOW;
public SpriteRenderer sprite;
//Referezenen
private Boli_Start Boliscript;
private Dialogbox Dialog;
private FadeScript Fadescript;
//Fade in and Out
// Use this for initialization
void Start ()
{
Boliscript = GameObject.FindGameObjectWithTag ("Schnecke").GetComponent<Boli_Start> (); //hier: Boli mit "Schnecke" betagged
Dialog = GameObject.FindGameObjectWithTag("CanvasTag").GetComponent<Dialogbox>();
Button_Erde.GetComponent<CanvasGroup>().alpha = 0;
Button_Erde.GetComponent<CanvasGroup> ().interactable = false;
Inputfield_Frage.GetComponent<CanvasGroup> ().alpha = 0;
Inputfield_Frage.GetComponent<CanvasGroup> ().interactable = false;
Fadescript = GameObject.Find ("BLACK").GetComponent<FadeScript> ();
}
// Update is called once per frame
void Update ()
{
if (Boliscript.redenB)
{
if (Dialog.NextOK == 0)
{
Button_E_Text.GetComponent<Text> ().text = Dialog.ButtonE_Text_NextOK00;
Button_A_Text.GetComponent<Text> ().text = Dialog.ButtonA_Text_NextOK00;
}
StartCoroutine ("WaitANDShowButtons");
if (Dialog.NextOK == 1)
{
StartCoroutine ("WaitANDShowInputfield");
if (Inputfiel_SetActiveFalse)
{
Inputfield_Frage.GetComponent<CanvasGroup> ().alpha = 1;
Inputfield_Frage.GetComponent<CanvasGroup> ().interactable = true;
Button_Erde.GetComponent<CanvasGroup> ().interactable = false;
Button_Alter.GetComponent<CanvasGroup> ().interactable = false;
Button_Erde.GetComponent<CanvasGroup> ().alpha = 0;
Button_Alter.GetComponent<CanvasGroup> ().alpha = 0;
}
Button_Erde.SetActive (false);
Button_Alter.SetActive (false);
}
}
//Boli redet nicht mehr
if (Dialog.NextOK == 2)
{
Inputfield_Frage.SetActive (false);
StartCoroutine ("SetButtonsActiveAgain");
}
if (Dialog.NextOK == 3)
{
StartCoroutine ("ShowNightskyAfterSeconds");
if (showNachthimmel)
{
//lässt Nachthimmel auf die Bildschirmgrösse verändern und Position perfekt an MainCamera anpassen.
var NachtSR = Nachthimmel.GetComponent<SpriteRenderer> (); //sr steht für Sprite Renderer
Nachthimmel.transform.localScale = new Vector3 (1, 1, 1); // Zuerst eine einheitliche Grösse machen
var width = NachtSR.sprite.bounds.size.x;
var height = NachtSR.sprite.bounds.size.y;
var worldScreenHeight = Camera.main.orthographicSize * 2.5f;//2.5f ist ein random Wert. halt so, dass dei Höhe passt.
var worldScreenWidth = worldScreenHeight / Screen.height * Screen.width;
double NachthimmelScaleX = Nachthimmel.transform.localScale.x;
double NachthimmelScaleY = Nachthimmel.transform.localScale.y;
NachthimmelScaleX = worldScreenWidth / width;
NachthimmelScaleY = worldScreenHeight / height;
Nachthimmel.transform.localScale = new Vector2 ((float)worldScreenWidth, (float)worldScreenHeight);
Nachthimmel.transform.position = new Vector2 (Camera.main.transform.position.x, Camera.main.transform.position.y);
}
showNachthimmel = false;
}
}
//Da der Text erst nach dem clicken auf den Button geändert wird, ist das die beste Lösung(Text ändert als Funktion bei Button Click der vorherigen NextOK-Phase)
public void ButtonTextChanger()
{
if (Dialog.NextOK == 1)
{
Button_E_Text.GetComponent<Text> ().text = Dialog.ButtonE_Text_NextOK1;
Button_A_Text.GetComponent<Text> ().text = Dialog.ButtonA_Text_NextOK1;
}
}
IEnumerator WaitANDShowButtons()
{
if (Dialog.NextOK == 0)
{
yield return new WaitForSeconds (ZeitBisButtonSHOW);
Button_Erde.GetComponent<CanvasGroup> ().alpha = 1;
Button_Erde.GetComponent<CanvasGroup> ().interactable = true;
Button_Alter.GetComponent<CanvasGroup> ().alpha = 1;
Button_Alter.GetComponent<CanvasGroup> ().interactable = true;
}
}
IEnumerator WaitANDShowInputfield()
{
yield return new WaitForSeconds (ZeitBisButtonSHOW);
Inputfiel_SetActiveFalse = true;
}
IEnumerator ShowNightskyAfterSeconds()
{
yield return new WaitForSeconds (3);
Fadescript.fadeBlack = true;
yield return new WaitForSeconds (fadeWartezeit);
showNachthimmel = true;
}
IEnumerator SetButtonsActiveAgain()
{
yield return new WaitForSeconds (2);
Button_Erde.GetComponent<CanvasGroup> ().alpha = 1;
Button_Erde.GetComponent<CanvasGroup> ().interactable = true;
Button_Alter.GetComponent<CanvasGroup> ().alpha = 1;
Button_Alter.GetComponent<CanvasGroup> ().interactable = true;
Button_E_Text.GetComponent<Text>().text = Dialog.ButtonE_Text_NextOK1;
Button_A_Text.GetComponent<Text>().text = Dialog.ButtonA_Text_NextOK1;
}
}
Comment