纳金网

标题: Unity3D获得两GameObject间距 [打印本页]

作者: 王者再临    时间: 2015-2-27 00:47
标题: Unity3D获得两GameObject间距

Unity3D获得两GameObject间距
  1. //******************************************************

  2. var a:GameObject;

  3. var b:GameObject;

  4. //a,b 分别定义两个公共GameObject对象//

  5. function Update () {

  6. if (a==null || b==null) {

  7. print(“a or b = null”);

  8. return;

  9. //如果a或者是b实例化失败就跳出函数

  10. }

  11. var m:Vector3;

  12. var n:Vector3;

  13. //m,n定义两个私有 Vector3类型

  14. m=a.transform.position;

  15. n=b.transform.position;

  16. //赋m,n予a,b的位置

  17. print(Vector3.Distance(m,n));

  18. //函数Vector3.Distance计算a,b间距,并在控制台输出

  19. }
复制代码





欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5