i need to show fps on the android test devices, i have tried several scripts including those from the wiki, they all work fine in the editor but wont display on any of the android devices, usb debugging is set on the test devices.
I use this script
using UnityEngine;
using System.Collections;
public class MobileUtilsScript : MonoBehaviour {
private int FramesPerSec;
private float frequency = 1.0f;
private string fps;
void Start(){
StartCoroutine(FPS());
}
private IEnumerator FPS() {
for(;;){
// Capture frame-per-second
int lastFrameCount = Time.frameCount;
float lastTime = Time.realtimeSinceStartup;
yield return new WaitForSeconds(frequency);
float timeSpan = Time.realtimeSinceStartup - lastTime;
int frameCount = Time.frameCount - lastFrameCount;
// Display it
fps = string.Format("FPS: {0}" , Mathf.RoundToInt(frameCount / timeSpan));
}
}
void OnGUI(){
GUI.Label(new Rect(Screen.width - 100,10,150,20), fps);
}
}
cheers i will give it a go and report back.
tried above code but still cant get it to work on any of my android devices, it works in the unity editor but not on devices, build is set to developement, debug is on and connected.
Maybe the rect isn’t showing up on screen, or is very small. I’d recommend trying using the new gui, and setting it to scale with screen, then try it. Everything seems like it should work fine on mobile.
Or try this:
http://wiki.unity3d.com/index.php?title=FramesPerSecond
already tried the wiki scripts, seems i have tried about 9 different fps display scripts that all work in the unity editor but just will not display on my android devices, getting hard to understand wht i am doing wrong, i am building using developement build on, all devices have debug mode on , and when tested are connected via usb, the builds run on the device except for the fps display, have i taken all steps or is there something i am not doing?
i am using unity 5.3, maybe it is to do with the rect and it is just staying tiny and cant be seen but i dont see why it would.
thanks
I’m a little confused. You keep saying the fps scripts do not work, but how do you normally display text onscreen?
The old OnGUI method might result in small text (although still visible, i’m sure) but you can also use the new uGUI.
Btw, i believe for the OnGUI method, you also need the GUILayer component attached to a camera
all i do is apply the above script to an empty game object in my scene, when run in the unity editor the fps is displayed, when i build the android and run it on my devices the fps is not displayed
Ok, but how about other texts? Can you see those?
i.e
using UnityEngine;
using System.Collections;
public class SampleScript : MonoBehaviour {
void OnGUI(){
GUI.Label(new Rect(10,10,150,30), "Test123");
}
}
Tested above test and the fps code above in a blank project and both worked fine, i guess for some reason the fps is not showing when i put it in an existing project on android for some reason, thanks
I’d say it’s really likely the old gui is just drawing really small, or offscreen. Happened to me before where I thought for the life of me that some gui was just not drawing on mobile, came to find it was, just so small I could not see it
So - maybe try NOT USING the old gui lol, and create a canvas with the new gui. Then create a text, set the canvas to scale with screen size, make it somewhat large, anchored to a corner but with some padding, and use that to display the fps rather than OnGUI calls…
Might just work!
Might I also recommend the free asset “lunar mobile console”, it’ll read out unity errors in real time during play if there so happens to be something going wrong on mobile, you’ll know about it.
thanks for the tips i will give them a try…
You might want to get more informations from your android build in the future (logs, device specs…)
May I suggest you something like this? I find it very convenient to get informations from a device build.
To actually display the FPS at all time you can get a reference from the Reporter GameObject and use its fpsText property. Something like this in an OnGUI script should do:
GUIStyle style = newGUIStyle();
Rect rect = newRect(0,0,Screen.width,Screen.height*2/100);
style.alignment = TextAnchor.UpperLeft;
style.fontSize = Screen.height*4/100;
style.normal.textColor = newColor(1.0f,1.0f,1.0f,1.0f);
string text = reporter.fpsText;
GUI.Label(rect,text,style);
Hello !!
i have this problem in my game pleas give some solution for it
i have a mobile game i made it in unity contain from 6 scenes and when i start the game the loading scene appear then the home then i click on start to translate from home scene to environment here i will choose the penalty scene and play on it then click exit and turn to environment to choose the match when i click on match first there is delay on open it and the player movement is so slowly but when i click on match without i click on penalty and play on it the match would not delay and the movement of player very suitable
Make your own thread. Don’t post on somebody else’s thread from eight years ago. Be clear. Use sentences.