最近在做不规则物体的直径方面的,比如血管的直径,不规则物体的长宽高,这方面的,
主要运用顶点之间的关系进行测量的。
代码如下:
using UnityEngine;
using System.Collections;
using System.Collections;
public class b : MonoBehaviour
{
{
// Use this for initialization
public Collider cd;
void Start()
{
cd = GetComponent<MeshCollider>();
Debug.Log("X:"+ cd.bounds.size.x);
Debug.Log("Y:"+ cd.bounds.size.y);
Debug.Log(":"+ cd.bounds.size.z);
}
public Collider cd;
void Start()
{
cd = GetComponent<MeshCollider>();
Debug.Log("X:"+ cd.bounds.size.x);
Debug.Log("Y:"+ cd.bounds.size.y);
Debug.Log(":"+ cd.bounds.size.z);
}
// Update is called once per frame
void Update()
{
}
}
void Update()
{
}
}
首要要获取Collider : 有两种方法 :写脚本 cd = GetComponent(); 另一种就是直接在图形界面中拖入。 然后记住 cd.bounds.size.x 就好了。
Transform 中的scale乘上初始尺寸就为实际长度了。
(如果初始值为0,那么改变scale就不会有变化,就像相机)