Hey guys, how are you? I starting play with unity yesterday, i come from cocos2d / Actionscript 3! Using C# to program, i start a little project just to know the platform and thing i can do, but something just don’t make sense to me!
Lets start with something simple:
I create a bunch of cubes make one big cube like these:
This was created by the following code:
void createSphere ()
{
float mainDelay = 0f;
float startX = -2.5f;
float startY = -2.5f;
float startZ = 8f;
for(int y = 0; y < 6 ; y++)
{
for (int z = 0; z < 6; z++)
{
for ( int x = 0; x < 6; x++)
{
GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.transform.position = new Vector3(x+(0.1f*x)+startX, 15+startY, z+(0.1f*z)+startZ);
float targetY = y+(0.1f*y)+startY;
int rand = Random.Range(1,4);
switch(rand)
{
case 1:
cube.transform.renderer.material.color = Color.red;
break;
case 2:
cube.transform.renderer.material.color = Color.blue;
break;
case 3:
cube.transform.renderer.material.color = Color.green;
break;
}
mainDelay += 0.2f;
iTween.MoveTo(cube, iTween.Hash("y", targetY, "time", 0.2, "easeType", "bounce", "delay", mainDelay/10));
}
}
}
}
Ok this was easy, now i want to rotate de cube when the user interact, the first problem! I can’t findo some object to hold all cubes itself, like a MovieClip (AS3) or a Layer (cocos2d).
Searching around the web i found this:
GameObject cubesHolder = new GameObject("cubesHolder");
cube.transform.parent = cubesHolder.transform;
Send each cube inside this object the Hierarchy star absolute right, exactly what i want:
But this just hold everything together on the Hierarchy, if i move the cube, when things are falling, they lost and things starting falling in the wrong place:
This just don’t make sense, since the positions are relative to the world!!
How i can create a object inside another? And this stay inside this object?
And how i can make the cube rotate around himself like this:
Like if i moving the yellow like?