Unity - A计划(一年有效期) 扫二维码继续学习 二维码时效为半小时

(66评价)
价格: 1299.00元
1对1 答疑即时回复7天无理由退款30天价保提问必答

服务保障

1对1 答疑

提供专属的一对一在线答疑,快速答疑解惑。

即时回复

及时响应学习咨询,帮助解决问题。

7天无理由退款

购买后7天内可申请无理由退款。

30天价保

购买后30天内如遇降价,可申请价保。

提问必答

对于提问做到有问必答,帮您扫清学习过程中的种种障碍

任务35:208-for、while和dowhile循环课程里面的问题
a1157360发起了问答2018-02-22
3
回复
541
浏览

老师,有个问题,children[i]不是返回的游戏物体么,为什么if判断的时候是 if (children[i] != transform),而不是 if (children[i] != Learn),我不明白transform是游戏物体里面的组件啊

 

 

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

public class Leran04_for_while : MonoBehaviour {

    // Use this for initialization
    void Start () {
        Transform[] children = transform.GetComponentsInChildren<Transform>();
        for (int i = 0; i < children.Length; i++)
        {
            if (children[i] != transform) {
                GameObject.Destroy(children[i].gameObject);
            }
        }
    }
    
    // Update is called once per frame
    void Update () {
        
    }
}

所有回复
  • 老师_Bathur • 2018-02-22

    Transform[] children

    这个决定了

    children[i]返回的是Transform组件

    • a1157360 • 2018-02-22

      但这些子物体的Transform组件都是这个名字啊

      (0) 回复
    • 老师_Bathur • 2018-02-22

      回复 @ a1157360: 您好,还是不太能够理解您的问题,children[i] != Learn中的Learn是什么呢?什么叫这些子物体的Transform组件都是这个名字呢?children[i] != transform中的transform是指当前脚本所在游戏物体身上的Transform组件

      (0) 回复
    还有-3条回复,点击查看
    你还没有登录,请先登录或注册!
发表回复
你还没有登录,请先 登录或 注册!