首先我很不解为什么Unity开发者没有游戏对象的尺寸表示出来,为开发精确性比较高的游戏增加了难度。因此一番摸索终于搞懂了这玩意。
Unity3D中的物体都是以米为单位来计算的,比如 cube的x,y,z都为1米,而plane的x=z=10,y=0.
using UnityEngine;
using System.Collections;
public class move : MonoBehaviour {
// Use this for initialization
public Collider cd;
void Start () {
cd = GetComponent<BoxCollider>();
Debug.Log(cd.bounds.size.x);
Debug.Log(cd.bounds.size.y);
Debug.Log(cd.bounds.size.z);
}
// Update is called once per frame
void Update () {
}
}
首要要获取Collider : 有两种方法 :写脚本 cd = GetComponent(); 另一种就是直接在图形界面中拖入。 然后记住 cd.bounds.size.x 就好了。
Transform 中的scale乘上初始尺寸就为实际长度了。
(如果初始值为0,那么改变scale就不会有变化,就像相机)