It’s a small 2D game with a score text (new gui element)
The score appears in the editor (Game mode) but disappears after build.
What could it be the cause?
It’s a small 2D game with a score text (new gui element)
The score appears in the editor (Game mode) but disappears after build.
What could it be the cause?
I am using unity 5
Have to attempted to contact a Psychic about this? Because you are going to need a Psychic unless you post some code we can look at to debug it!
Because it’s not a code-related issue; it is working fine on editor, I feel it’s a camera related and positioning of the UI text.
Are other elements keeping their positions ? (Try adding some UI object in each corner for example…)
Are you using some UI scaling?
What resolution the view is in editor and what resolution in the game?
Screenshots?
I am away from my pc now,
it is the only UI element and it’s anchored with the canvas on upper left.
It’s positioned in posz at minus something (it was a huge nb like -1000) while the background’s Z is 0.
it is visible in play mode on the editor, but on the Android it is not (but the whole background is correctly visible).
What’s exactly UI scaling? I don’t think I used it. I will google it.
It was the only UI element.
The resoluion on editor is set to 1080x1920 portrait and the UI is visible in play mode, but when the game was tested on both Bluestacks and Nexus5’s simulation, the UI text disappeared.
the background and the non-UI objects looked fine.
Will provide screenshots when i can.
Ok here are my screenshots:
This is on the editor: I am showing background’s position and the UI text’s position:
and that’s the camera:
And that’s the troubling UI text:
And that’s the script related to the scoring, I am certain it’s not a script issue tho:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class DestroyOnClick : MonoBehaviour {
void OnMouseDown()
{
GameObject gc = GameObject.Find("GameController");
GCScript gcsript = gc.GetComponent<GCScript>();
if(this.gameObject.name == "PinkBalloon(Clone)"){
gcsript.Add1Point (); }
else if(this.gameObject.name == "RedBalloon(Clone)"){
gcsript.Add2Point (); }
else if(this.gameObject.name == "GreenBalloon(Clone)"){
gcsript.Add3Point (); }
else if(this.gameObject.name == "OrangeBalloon(Clone)"){
gcsript.Add4Point (); }
else if(this.gameObject.name == "BlueBalloon(Clone)"){
gcsript.Add5Point (); }
Destroy(this.gameObject);
}
}
Which calls the following function in another script to update score:
public void Add1Point() {
count = count + 1;
countText.text = "Count: " + count.ToString();
color = "pink";
Bal = PBal;
Sequence ();
It’s working fine in editor, Game mode:
but on any Android after build, it doesn’t, I don’t understand why:
You can see the same cloud that has the score text is finely visible, the cloud is part of the background and not a separate object.
I am no programmer so sorry if my code looks kinda messy.
Whenever I had trouble with UI or anything else not showing up; it was because of the Z position (in an 2D environment).
Try changing the Z position value of the text that is not appearing - noticed it was -1751.4. Try changing it to -1 or 1 or something near those numbers
I will try this when i get home.
I did suspect it was about the Z, but I didn’t get this -1751.4. by chance, it was actually by trial and error (by dragging it manually till it appears on camera in 2D). When switching to 3D on editor, you can actually see the UI Text just in front of the background by little.
I’ve read somewhere that the position of UI not measured in the same way of normal objects, so confusing! How comes -Ui’s Z -1751 is equivalent to almost 1 for bkg’s Z?
http://docs.unity3d.com/Manual/class-RectTransform.html
but in my case its parent is…the canvas? I am not sure if I get that right, and how to reposition the canvas if it’s the case?
OK! I got it solved!! And here’s how!
The answer is there in what I quoted from unity docs:
At first, when I switched to 3D, I’ve noticed the canvas was stupidly way behind the background:
As you can see, the Canvas’ pos Z is 90.3, so that’s WHY the UI Text 's Z was -1751.4, because its Z position relative to its parent the canvas!!
To fix that, all I needed to do is to adjust the Plane Distance of the Canvas till it’s just in front of the background, then you the distance of text like -1, and that’s it!!!
And voila!!
Glad it worked!