# Move all objects once one reaches a boundry

I’m currently trying to resimulate Space Invaders, however, I’m having difficulty moving all of the invaders down once one of them reaches the end. I can do it in a ‘snake’ like effect, where they all follow the boundary and drop by themselves, once they’ve reached it. But that is not the effect I want to achieve.

Would someone kindly be able to explain like I’m five how I should go about achieving the effect I need?

If possible some sample could would be fantastic - so I can educate myself on how to achieve this. Thank you for your time.

``````using UnityEngine;
using System.Collections;

public class enemyMovement : MonoBehaviour
{
//spawn random range for position / amount to spawn.
public float leftRightSpeed;
public float boundaryLeft = -10.0f;
public float boundaryRight = 10.0f;

public bool WeShouldGoRight = true;

public Vector3 dropAmount = new Vector3(0, 0, 0); //set in interface

public Transform myTransform;

// Update is called once per frame
void Update()
{
MovementDetection();

Move(WeShouldGoRight);
}

void Move(bool moveRight)
{
float movementX = moveRight ? leftRightSpeed : -leftRightSpeed;
transform.Translate(new Vector3(movementX * Time.deltaTime, 0, 0));
}

void DropALevel()
{
transform.Translate(dropAmount);
}

void MovementDetection()
{
if ((transform.position.x >= boundaryRight) || (transform.position.x <= boundaryLeft))
{
// A boundary has been reached; swap the travel direction and move down a level.
WeShouldGoRight = !WeShouldGoRight;

DropALevel();

Debug.Log("Switching directions; now moving" + (WeShouldGoRight ? "Right" : "Left"));
}
}
}
``````

One way to approach it (and make sure you have a safety in place so multiple don’t trigger it simultaneously), is to use BroadcastMessage to tell the other units to move down. That way, you can have each (or single out ones currently on the ends) detect if it’s on the edge and, if it is, tell all units to move down.