I recently started to learn Unity a few days ago, have already learned a lot through Q&A on this site, and tutorials.
I’m making a dummy game to learn to make endless runners with seamless terrains. I’ve got colliders good, terrains are seamless. The one annoying issue I’m having is a simple, no-brainer Label.
I’m sorting through the Android resolution problems and text size issues. The label is telling how far my cube travels. This question is more of a convenience type issue, as it works on my GS4 without any issues, but the label does not display in the Game tab in Unity.
Here is my code:
using UnityEngine;
using System.Collections;
public class metersScript : MonoBehaviour {
static int width = Screen.width;
static int height = Screen.height;
public GUIStyle foureighty;
public GUIStyle eighthundred;
public GUIStyle thousandtwentyfour;
public GUIStyle twelveeighty;
public GUIStyle nineteentwenty;
public int meters;
public Transform target;
void Update(){
meters = (int)target.transform.position.x;
}
void OnGUI(){
if (width == 480) {
GUI.Label(new Rect(width/width * 10, height/height * 10, 100,50), meters + "M", foureighty);
} else if (width == 800) {
GUI.Label(new Rect(width/width * 10, height/height * 10, 100,50), "1602M", eighthundred);
} else if (width == 1024) {
GUI.Label(new Rect(width/width * 10, height/height * 10, 100,50), "1703M", thousandtwentyfour);
} else if (width == 1280) {
GUI.Label(new Rect(width/width * 10, height/height * 10, 100,50), "1804M", twelveeighty);
} else if (width == 1920) {
GUI.Label(new Rect(width/width * 10, height/height * 10, 100,50), meters + "M", nineteentwenty);
}
}
}
For some reason, only the 480 width is working in the Game tab, the 1920 doesn’t work in the Game tab but it does work on my phone when I build and run it.
Any advice is appreciated.