Hi everybody
I’m a beginner with Unity and I’m struggeling with a problem. I’m working on a 3D Tetris and I’m working on the code, that moves the blocks 1 unit per second.
Here is my code so far (the movementscript is on the bottom):
#pragma strict
var startingPoint : GameObject;
var block1 : GameObject;
var block2 : GameObject;
var block3 : GameObject;
var block4 : GameObject;
var moving : GameObject;
private var randomObject : int;
private var block : GameObject;
static var isSet = false;
private var zaehler = 1;
function Update () {
if(!isSet) //Check if ther is already an active Block
{
//Set random block
randomObject = Mathf.Round(Random.Range(1.0,4.0));
switch (randomObject)
{
case 1.0:
block = block1;
break;
case 2:
block = block2;
break;
case 3:
block = block3;
break;
case 4:
block = block4;
break;
}
//Instantiate Block
Instantiate(block, startingPoint.transform.position, startingPoint.transform.rotation);
//setting active to true
isSet = true;
}
while(isSet)
{
if (zaehler > 1000)
{
break;
}
//here is the moving script
block.transform.Translate(0,Time.deltaTime,0,Space.World);
zaehler++;
Debug.Log(block.transform.position);
}
}
The debugger doesn’t show any error. The Debug.Log shows, that the transform.position is changing but the block is not moving.
Why not? I tried different versions (as mentioned in the reference) for the Translate script but none of them worked.
The while loop is in there cause I need it later.
Thanks for your help
mitti2000
The "block" variable doesn't seem to be set to anything. It's declared but never initialized. Also, http://forum.unity3d.com/threads/5105-Gravity-3d-Tetris?p=38267&viewfull=1#post38267
– Eric5h5