我创建了一个游戏,里面有16个球体,它们在鼠标点击时交换。但是我希望有15个球体和一个空的游戏对象,以便在空游戏对象的帮助下滑动它们。我还想在每次游戏开始时随机播放球体。这怎么可能?
之后我尝试制作它,但我的立方体在开始时改变它们的位置时相互重叠。
var xtemp ;
var ytemp ;
var slot : Transform;
var cubesPosition : Vector3[] = new Vector3[16];
var cubeGameObjects: GameObject[] = new GameObject[16];
function Start ()
{
ChangePosition();
AssignPositions();
}
function ChangePosition()
{
for(var i=0;i<cubeGameObjects.length;i++)
{
cubeGameObjects[i].transform.position;
}
slot.transform.position = new Vector3(Random.Range (1,4),Random.Range (1,4),10);
}
function AssignPositions()
{
for (var i = 0; i < cubesPosition.length; ++i)
cubeGameObjects[i].transform.position = cubesPosition[i];
}
function OnMouseUp() {
if(Vector3.Distance(transform.position,slot.position)==1)
{
xtemp = transform.position.x;
ytemp = transform.position.y;
transform.position.x=slot.position.x;
transform.position.y=slot.position.y;
slot.position.x = xtemp;
slot.position.y = ytemp;
}