您的位置:首页 > 移动开发 > Unity3D

Unity3d--GetComponent的使用方法

2016-04-10 20:28 537 查看
Unity3d--GetComponent的使用方法



using UnityEngine;
using System.Collections;

public class Test : MonoBehaviour {

private Quaternion[] quaters;
private Color[] colors;
private Material mr;

void Awake(){
quaters = new Quaternion[7];
colors = new Color[7];
}

void Start () {
int i = 0;
while (i<quaters.Length) {
quaters [i] = Random.rotationUniform;
colors[i] = new Color (Random.value, Random.value, Random.value);
Transform child = this.transform.GetChild (i);
child.rotation = quaters [i];
//获取物体组件,修改组件参数值。
child.GetComponent<MeshRenderer> ().material.color = colors [i];
i++;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: