为什么运行起来一直不对
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour {
Transform translight;
Transform translight2;
public Transform TransRoot;
// Use this for initialization
void Start () {
FindChild(TransRoot, "Light1", ref translight);
FindChild(TransRoot, "Light2", ref translight2);
translight.GetComponent<Light>().color = Color.red;
}
/// <summary>
/// 寻找物体
/// </summary>
/// <param name="trans">作为父物体的transform</param>
/// <param name="findName">寻找的物体名称</param>
/// <param name="_trans">找到的物体</param>
void FindChild(Transform trans,string findName,ref Transform _trans)
{
if (trans.name.Equals(findName))
{
_trans = trans.transform;
return;
}
if (trans.childCount != 0)
{
for(int i = 0, length = trans.childCount; i <length; i++)
{
FindChild(trans.GetChild(i), findName, ref _trans);
}
}
}
// Update is called once per frame
void Update () {
}
}