- Home /
iTween MoveBy with Transforms
Hello, a friend helped me code a function which loops through an empty game object where all my game objects (that move) are stored. It seems that these game objects are stored in the transform of empty game object container.
private function handleButtonClick(columnIncrementer:int, rowIncrementer:int) { for (var child:Transform in container.transform) {
var currentColumn:int = Mathf.Floor(child.position.z / cellSize);
var currentRow:int = Mathf.Floor(child.position.x / cellSize);
var openColumnIndex:int = currentColumn + columnIncrementer;
var openRowIndex:int = currentRow + rowIncrementer;
while (checkIfBlockOccupied(openColumnIndex, openRowIndex) == true && openColumnIndex > -1 && openRowIndex > -1 && openColumnIndex < columns && openRowIndex < rows)
{
openColumnIndex += columnIncrementer;
openRowIndex += rowIncrementer;
}
if (openColumnIndex > -1 && openRowIndex > -1 && openColumnIndex < columns && openRowIndex < rows)
{
<b>setBlockPosition(child, currentColumn + columnIncrementer, currentRow + rowIncrementer);</b>
}
......
</pre>
Now I would like to use iTween's MoveTo function to animate my cubes in the setBlockPosition function:
private function setBlockPosition(child:Transform, column:int, row:int) : void { iTween.MoveTo(child, Vector3(row * cellSize, 0, column * cellSize), 2.0); }
The error:
No appropriate version of iTween.MoveBy for the argument list..
. This function requires a reference to a game object but it seems that my cube game objects are seen as a transform component. Is this thinking correct? I have tried using child.GameObject but this does not work either. Thoughts?
Answer by $$anonymous$$ · Jul 22, 2012 at 08:40 AM
For anybody who is interested, here is the answer -
The answer is to use child.gameObject and not child.GameObject as gameObject is the instance of the GameObject class. So:
iTween.MoveTo(child.gameObject, Vector3(row * cellSize, 0, column * cellSize), 2.0);
Your answer
Follow this Question
Related Questions
Instantiate rigidbody, transform or gameobject? 1 Answer
I want to move a cube with rotation but I find this problem 1 Answer
Can I move a component from one GameObject to another in script? 1 Answer
Is there any way to convert Collision to a Gameobject or Transform? 1 Answer
Difference between Vector3, Transform and GameObject 2 Answers