using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ArrayOverview : MonoBehaviour
{
public GameObject[] cubes;// 初始化一个游戏对象的数组,用于存放方块对象
public Color[] cubeColors = new Color[]{ Color.red, Color.blue, Color.yellow };// Start is called before the first frame updatevoidStart(){}// Update is called once per framevoidUpdate(){if(Input.GetKeyUp(KeyCode.Space))// 按下空格键{int colorID = Random.Range(0, cubeColors.Length);// 随机颜色for(int i =0; i<cubes.Length; i++){
cubes[i].GetComponent<MeshRenderer>().material.color = cubeColors[colorID];// 遍历 cube 设定为统一的颜色}}}}