您当前的位置: 首页 >  unity

鱼儿-1226

暂无认证

  • 0浏览

    0关注

    1100博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

unity找到指定名称的一个物体的子物体,多个子物体有相同的名称

鱼儿-1226 发布时间:2022-06-08 15:26:17 ,浏览量:0

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Roation : MonoBehaviour {


	//要找子物体的那个物体
	private GameObject game;
	public Transform parent, tracker;
	//想找的子物体的名字
	public string childName;

	// Use this for initialization
	void Start () {
		childName = "Cube";
		game = GameObject.Find ("Plan01");

		tracker = GetTransform(game.transform, childName);
	}

	// Update is called once per frame
	void Update () {
		tracker.Rotate (new Vector3(0, 1, 0), 3);
		tracker.RotateAround (new Vector3(0, 0, 0), new Vector3(0, 1, 0), 1);

	}

	Transform GetTransform(Transform check, string name)
	{
		foreach (Transform t in check.GetComponentsInChildren())
		{
			if (t.name == name) 
			{
				//要做的事
				Debug.Log(t.name);



				return t;    
			}    
		}
		return null;
	}


}

 

关注
打赏
1604459285
查看更多评论
立即登录/注册

微信扫码登录

0.0599s