标签:
#pragma strict
var speed : float = 100;
var m_LastUpdateShowTime : float = 0f; //上一次更新帧率的时间;
var m_UpdateShowDeltaTime : float =0.01f;//更新帧率的时间间隔;
var m_FrameUpdate : int = 0;//帧数
var m_FPS : float = 0;
function Awake ()
{
Application.targetFrameRate = 100;
}
function Start () {
m_LastUpdateShowTime=Time.realtimeSinceStartup;
}
function Update () {
var x:float = Input.GetAxis("Horizontal") * Time.deltaTime * speed;
var z:float = Input.GetAxis("Vertical") *Time.deltaTime * speed;
transform.Translate(x,0,z);
m_FrameUpdate++;
if(Time.realtimeSinceStartup-m_LastUpdateShowTime>=m_UpdateShowDeltaTime)
{
m_FPS=m_FrameUpdate/(Time.realtimeSinceStartup-m_LastUpdateShowTime);
m_FrameUpdate=0;
m_LastUpdateShowTime=Time.realtimeSinceStartup;
}
}
function OnGUI() {
GUI.Label(new Rect(Screen.width/2,0,200,100),"FPS: "+m_FPS);
}
unity 创建第一个JavaScript 脚本,附加物体之上 利用键盘 对物体进行移动 以及帧率显示
标签:
原文地址:http://www.cnblogs.com/lalalahahaha/p/5826785.html