今日も主に↓のサイトでお勉強
http://www40.atwiki.jp/spellbound/pages/1303.html
今後定期的に使いそうなコード
アセットとして残してるけど、折角なので書き残しておく
・左クリックした際のマウスカーソルの3次元座標計算
public GameObject mPrefab; public Camera mCamera; public float mVecZ = 10.0f; Vector3 mMouseVec = Vector3.zero; // 左クリック if( Input.GetMouseButtonDown(0) ){ mMouseVec = Input.mousePosition; // マウスカーソル位置を取得 mMouseVec.z = mVecZ; // カメラからのZ距離 mMouseVec = mCamera.ScreenToWorldPoint( mMouseVec ); // スクリーン -> ワールド Instantiate( mPrefab, mMouseVec, Quaternion.identity ); // 指定したプレハブを計算した座標に生成 }
・FPS計測
using UnityEngine; using System.Collections; public class FpsCounter : MonoBehaviour { public float mUpdateInterval = 1.0f; // 更新される頻度 int mNumFrame = 0; // フレーム数 float mTimeCounter = 0.0f; // 計測用カウンター float mTimer = 0.0f; // タイマー float mFps = 0.0f; // Use this for initialization void Start () { mTimeCounter = mUpdateInterval; guiText.text = "FPS:" + 0 + " ( " + 0 * 1000.0f + "ms )" ; } // Update is called once per frame void Update () { // 1フレームの時間 mTimeCounter -= Time.deltaTime; mTimer += Time.timeScale / Time.deltaTime; // 時間間隔 / 1フレームの時間 mNumFrame++; // if( mTimeCounter < 0.0f ){ mFps = mTimer / mNumFrame; guiText.text = "FPS:" + mFps.ToString() + " ( " + 1.0f / mFps * 1000.0f + "ms )" ; mNumFrame = 0; mTimer = 0.0f; mTimeCounter = mUpdateInterval; } } }
・WebPlayerのテスト
クリックした座標にcube生成
https://dl.dropboxusercontent.com/u/30427841/Unity_web/0810/Desktop.html