Unity寻找子物体的几种方法

admin3年前unity基础API3339

    1: transform.Find()寻找子物体


   transform.Find(“子物体名字”)



2: GameObject.FindGameObjectWithTag() 通过标签获取物体 针对全局


3:transform.GetChild() 通过序号查找子物体


Debug.Log(transform.GetChild(0));

Debug.Log(transform.GetChild(1));

Debug.Log(transform.GetChild(0).GetChild(0));


4:查找子物体的组件

//查找全部

GetComponentsInChildren

    Rigidbody rigidbody =    GetComponentInChildren<Rigidbody>();

//查找一个

GetComponentInChildren


    
        Rigidbody[] rigidbodys = GetComponentsInChildren<Rigidbody>();
        foreach (var child in rigidbodys) {
            print("子物体名:"+child.name);
        }


相关文章

Unity 手机触摸Touch事件

1:判断是否触摸如果大于0那就是最少一个手指触摸了屏幕 以此类推 如果=2就是2个手指 最多10个if(Input.touchCount >0)2:判断单...

Unity移动操作物体

if (Input.touchCount == 1)         {  ...

Unity 插值运算

在unity3d中经常用线性插值函数Lerp()来在两者之间插值,两者之间可以是两个材质之间、两个向量之间、两个浮点数之间、两个颜色之间,其函数原型如下: 1.Material.Lerp&nbs...

blender导出模型和动画到Unity

blender导出模型和动画到Unity

1:首先我们确保导出的模型是FBX2:模型的Rig设置为泛型 avatar根据实际情况可以选择无或则从此模型创建3:设置动画控制器,把模型中的动画拖入就可以了...

unity 新的输入系统input system 使用

unity 新的输入系统input system 使用

1:首先在包管理器里安装 搜索"input system"2: 创建input acionts3:生成代码  勾选后点击右小角应用就可以自动生成相关代...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。