using UnityEngine; using System.Collections; /** * <summary> * <para>作者:巨星电艺</para> * <para>编写日期:巨星电艺</para> **/ public class ouyGridRandomColor : MonoBehaviour { public Transform CellPrefab; public Vector3 Size; public Transform[,,]Grid; // Use this for initialization void Start () { CreateGrid (); SetRandomNumbers (); // 测试一下对单单独一个点定位 Transform newCell; newCell = Grid[4,4,4]; // Color color = Color.black; color.r = 0f; color.g = 109f; color.b = 0f; color.a = 255f; newCell.GetComponent<MeshRenderer> ().material.color = new Color (color.r,color.g,color.b,color.a); } void CreateGrid () { Grid =new Transform[(int)Size.x,(int)Size.y,(int)Size.z]; for (int x = 0; x < Size.x; x++) { for (int y =0; y<Size.y; y++) { for(int z = 0; z < Size.z; z++) { Transform newCell; newCell = (Transform) Instantiate (CellPrefab, new Vector3(x,y,z),Quaternion.identity); newCell.name = string.Format( "({0},0,{0})",x,y,z); newCell.parent = transform; Grid[x,y,z] = newCell; } } } } void SetRandomNumbers () { byte r = 0; byte g = 0; byte b = 0; foreach (Transform child in transform) { //= Random.Range(0, 200); r = (byte) Random.Range(0, 255); g = (byte) Random.Range(0, 255); b = (byte) Random.Range(0, 255); child.GetComponent<MeshRenderer>().material.color = new Color32(r,g,b,255); //Debug.Log("weight = "+ weight); } } // Update is called once per frame void Update () { if (Input.GetKeyDown (KeyCode.F1)) { Application.LoadLevel(0); } } }