当前位置: 首页 > news >正文

html手机网站模板公司网站静态模板

html手机网站模板,公司网站静态模板,长春火车站在哪个区,深圳企业黄页网本文总结一下关于unity的查找子物体的方法 首先说明一下这里将讲三种查找子物体方法#xff1a; 查找固定路径的某一个子物体的方法、通过名字深度查找某个子物体的方法、查找父物体下所有子物体的方法。 第一:查找固定路径的某一个子物体的方法 对于已知的路径可以直接用go.t… 本文总结一下关于unity的查找子物体的方法   首先说明一下这里将讲三种查找子物体方法 查找固定路径的某一个子物体的方法、通过名字深度查找某个子物体的方法、查找父物体下所有子物体的方法。   第一:查找固定路径的某一个子物体的方法 对于已知的路径可以直接用go.transform.FindChild方法来查找。 例如在这样一个层级路径下我们要找到最后那个plane物体。   1 using UnityEngine;2 using System.Collections;3 4 public class findchild : MonoBehaviour {5 6 // Use this for initialization7 void Start () {8 9 } 10 11 // Update is called once per frame 12 void Update () { 13 if (Input.GetMouseButtonDown(1)) 14 { 15 //查找物体方法 16 GameObject go GameObject.Find(Cube); 17 //查找子物体并且将得到的物体转换成gameobject 18 GameObject objname go.transform.FindChild(Sphere/Cylinder/Plane).gameObject; 19 20 Debug.Log(得到最终子物体的名字是 objname.name); 21 } 22 } 23 }   然后是执行结果       -------------------------------------------------------------------------------------------------------------   第二通过名字深度查找某个子物体的方法 注意要使用这个方法必须要满足两个条件第一必须有你要查找的子物体的名字第二必须要从一个父物体上开始查起     下面代码中check代表从这个父物体开始查起name为你要查找的目标子物体的名称。如return GetTransform(transform,bone12); 该方法核心代码     而下面是查找的具体方法 1 Transform GetTransform(Transform check, string name)2 {3 Transform forreturn null;4 5 foreach (Transform t in check.GetComponentsInChildrenTransform())6 {7 if (t.name name)8 {9 Debug.Log(得到最终子物体的名字是 t.name); 10 forreturn t; 11 return t; 12 13 } 14 15 } 16 return forreturn; 17 }   再看完整的测试代码还用上个的例子的例如这次要查到Cylinder这个物体   修改后的代码 1 using UnityEngine;2 using System.Collections;3 4 public class findchild : MonoBehaviour {5 6 // Use this for initialization7 void Start () {8 9 } 10 11 // Update is called once per frame 12 void Update () { 13 if (Input.GetMouseButtonDown(1)) 14 { 15 // //查找物体方法 16 GameObject go GameObject.Find(Cube); 17 // //查找子物体并且将得到的物体转换成gameobject 18 //GameObject objname go.transform.FindChild(Sphere/Cylinder/Plane).gameObject; 19 20 //Debug.Log(得到最终子物体的名字是 objname.name); 21 22 23 GetTransform(go.transform, Cylinder); 24 25 } 26 } 27 28 Transform GetTransform(Transform check, string name) 29 { 30 Transform forreturn null; 31 32 foreach (Transform t in check.GetComponentsInChildrenTransform()) 33 { 34 if (t.name name) 35 { 36 Debug.Log(得到最终子物体的名字是 t.name); 37 forreturn t; 38 return t; 39 40 } 41 42 } 43 return forreturn; 44 } 45 }   测试结果   ----------------------------------------------------------------------------------------------------- 第三接下来我们将获取一个父物体下的所有子物体,然后销毁其下所有子物体 注意所有子物体都是同级关系在同一层里。如图   核心方法 1 ListTransform lst new ListTransform();2 foreach (Transform child in transform)3 {4 lst.Add(child);5 Debug.Log(child.gameObject.name);6 }7 for (int i 0; i lst.Count; i)8 {9 Destroy(lst[i].gameObject); 10 }   上面的transform就是该父物体的transform。具体案例代码 1 using UnityEngine;2 using System.Collections;3 using System.Collections.Generic;4 5 public class findchild : MonoBehaviour {6 7 // Use this for initialization8 void Start () {9 10 } 11 12 // Update is called once per frame 13 void Update () { 14 if (Input.GetMouseButtonDown(1)) 15 { 16 // //查找物体方法 17 GameObject go GameObject.Find(Cube); 18 ListTransform lst new ListTransform(); 19 foreach (Transform child in go.transform) 20 { 21 lst.Add(child); 22 Debug.Log(child.gameObject.name); 23 } 24 for (int i 0; i lst.Count; i) 25 { 26 Debug.Log(销毁的物体是 lst[i].gameObject); 27 Destroy(lst[i].gameObject); 28 } 29 30 } 31 } 32 33 34 } 测试结果全被销毁了     以上就是我总结的常用的三种查找子物体的方法。   转载于:https://www.cnblogs.com/macky/p/9335093.html
http://www.pierceye.com/news/568663/

相关文章:

  • 单页面营销网站怎么用polylang做网站
  • 网站开发入那个科目中国网站建设哪家公司好
  • 网站流量提升方案软件公司名称大全查询
  • 怎么做淘客专属网站济南公司网站推广优化最大的
  • 苏州网站建设极简幕枫织梦模板网站源码
  • 青岛网站设计定制2023传奇手游排行榜
  • 商务酒店网站建设淮南网备案查询
  • 菏泽炫佑网站建设中国城乡建设部网站
  • 网站开发与移动互联自助建站的优点与缺点
  • 公司做网站的好处上海网站设计找哪家
  • 个人如果做网站赚钱吗WordPress 聊天小工具
  • 商城网站建设哪家便宜网络架构师和网络工程师区别
  • p2p网站建设 深圳广东手机网站建设品牌
  • 亚马逊网上商城是正品吗长沙seo计费管理
  • 东莞品牌网站建设多少钱网站设计有限公司怎么样
  • dedecms新网站 上传到万网的空间浦口区网站建站公司
  • 龙岗在线网站建设西安房产信息网
  • 如何建立公司企业网站大朗做网站的
  • 怎么做整蛊网站wordpress系统的特点
  • php网站开发视频教程浙江建设局网站
  • 温州seo顾问温州网站优化排名推广
  • qq空间怎么做网站wordpress 分类名
  • 外贸国际网站推广重庆律师网站
  • 唐山建设信息网站wordpress 首页显示产品
  • 建设网站的公司哪个济南兴田德润怎么联系重庆短视频培训
  • 营销型网站的建设方案企业网页设计作品分析
  • 网站建设的费用报价做网站销售这几天你有什么想法
  • 做箱包关注哪个网站类似建站之星网站
  • 口碑好网站建设报价wordpress 微博侧边栏
  • 长沙 建站优化花都区手机版网站建设