Question by
millie2107 · May 17, 2017 at 12:49 PM ·
transform.positionvector2movetowards
How to move more than one object together at a time?
They suppose to move to a new position when hitting Z key but they all stuck together in a same position. Is there any way to solve this problem? Please help. Thanks in advance
public void moveEgg()
{
if (Input.GetKeyDown(KeyCode.Z))
{
transform.position = Vector2.MoveTowards(eggPositionLeft, EggSpawn.eggPosition[5], 0 * Time.deltaTime);
transform.position = Vector2.MoveTowards(EggSpawn.eggPosition[5], EggSpawn.eggPosition[4], 0 * Time.deltaTime);
transform.position = Vector2.MoveTowards(EggSpawn.eggPosition[4], EggSpawn.eggPosition[3], 0 * Time.deltaTime);
transform.position = Vector2.MoveTowards(EggSpawn.eggPosition[3], EggSpawn.eggPosition[2], 0 * Time.deltaTime);
transform.position = Vector2.MoveTowards(EggSpawn.eggPosition[2], EggSpawn.eggPosition[1], 0 * Time.deltaTime);
}
}
Comment
Answer by jdean300 · May 17, 2017 at 09:46 PM
You are passing in zero as the amount to move to the MoveTowards function: 0 * Time.deltaTime
. Pass in anything else, and they will move.