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();
}
// Update is called once per frame
void Update () {
cube.Move();
}
}
拓展:行 列 宽 生成cube.
```csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TopicCheck_JCWJ : MonoBehaviour
{
public Transform parent;
public static bool hasFinish;
public float startCount;//640 421
public static float finishCount;
private bool finish;
void Start()
{
Ins();
startCount = 200;
}
// Update is called once per frame
void Update()
{
if (transform.childCount < 221)
{
hasFinish = true;
}
else
{
hasFinish = false;
}
// 检测是否完成挖掘(不存在Collider在土里的情况)
if (CommonCheck.instance.isInWokeArea)
{
for (int i = 0; i < transform.childCount; i++)
{
finishCount = (transform.childCount - 221) / startCount;
if (transform.GetChild(i).GetComponent<FinishCheck>().isInSoil == false)
{
Destroy(transform.GetChild(i).gameObject);
}
}
Debug.Log(transform.childCount);
Debug.Log(finishCount);
}
if (hasFinish)
{
if (finish)
{
// 切换任务
View_TestCarUIForm._instance.ChangeTaskNEW(3);
// 完成基础定点挖掘作业
StaticCall.UpdateScore(3069);
CommonCheck.instance.hasFinishAll = true;
finish = false;
}
}
//Debug.Log(transform.childCount);
}
// Update is called once per frame
public float speed = 0.2f;
public GameObject[,,] cube = new GameObject[35, 40, 5];
public void Ins()
{
for (int i = 0; i < 16; i++)
{
for (int k = 0; k < 20; k++)
{
for (int j = 0; j < 2; j++)
{
cube[i, k, j] = MonoBehaviour.Instantiate<GameObject>(Resources.Load("CubeCheck_JCWJ") as GameObject, parent.position, parent.rotation, parent);
if (cube[i, k, j].GetComponent<FinishCheck>() == null)
{
cube[i, k, j].AddComponent<FinishCheck>();
}
if (cube[i, k, j].GetComponent<Rigidbody>() == null)
{
cube[i, k, j].AddComponent<Rigidbody>().isKinematic = true;
}
cube[i, k, j].transform.localPosition = new Vector3(i * 1f, j * 0.5f, k * 1f);
}
}
}
}
}