我糊塗了,這是我的創造,並記錄浮動升C腳本:統一調試日誌全浮
using UnityEngine;
using System.Collections;
public class guicontrol : MonoBehaviour {
void CalculatePosition(string ObjectName) {
GameObject theobject = GameObject.Find (ObjectName);
int selectedwidth = 1366;
int selectedheight = 768;
int screenwidth = Screen.width;
int screenheight = Screen.height;
float coordinatey = theobject.transform.localPosition.y;
float coordinatex = theobject.transform.localPosition.x;
float coordinatez = theobject.transform.localPosition.z;
Debug.Log ("work at current stats : " + screenwidth + " " + screenheight);
if (screenwidth != selectedwidth || screenheight != selectedheight) {
float coordinateytomove = (screenheight/selectedheight) * coordinatey;
float coordinatextomove = (screenwidth/selectedwidth) * coordinatex;
Debug.Log (coordinateytomove + " " + coordinatextomove);
}
}
}
當我在計算器手動計算的話,的coordinatextomove
結果是:
-2.99853587116
,但在調試日誌是:
-3 0
-3
是coordinateytomove
不從目前的變化的座標,但爲什麼如果coordinatextomove
改變,其調試記錄0
代替-2.99853587116
?如果有以前的帖子回答了這個問題,請原諒我,並給我鏈接的帖子:)。
如果你想在你可能想要做的'camera.WorldToScreenPoint(theobject.transform.position)屏幕的面積來選擇對象;',讓你的'coordinatex',並從'coordinatey'。這會給你遊戲對象屏幕上的x和y座標。 –