我糊涂了,这是我的创造,并记录浮动升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坐标。 –