using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Cube{
public float speed = 0.2f;
public GameObject[,] cube=new GameObject[6,6];
public void Ins()
{
for (int i = 0; i < 6; i++)
{
for (int k = 0; k < 6; k++)
{
cube[i, k] = MonoBehaviour.Instantiate<GameObject>(Resources.Load("Cube") as GameObject);
cube[i,k].transform.position = new Vector3(i * 2, 0, k * 2);
}
}
}
public void Move()
{
for (int i = 0; i < 6; i++)
{
for (int k = 0; k < 6; k++)
{
this.cube[i, k].transform.Translate(Input.GetAxis("Horizontal") * speed, 0, Input.GetAxis("Vertical") * speed);
this.cube[i,k].transform.Rotate(Input.GetAxis("Horizontal") * 15,0,0 );
}
}
}
}
下面这个我挂在了相机上
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Controller : MonoBehaviour {
Cube cube;
void Start () {
cube = new Cube();
cube.Ins();
}
void Update () {
cube.Move();
}
}

|