how to check character out of bound camera

Hi!
Im beginner with Unity,
In my game i want camera run from left to right automatic, can anybody help me trigger when character out of bound of camera (he left of camera)

Thanks :slight_smile:

If your game is a 2D side-scroller, you can compare the character’s position to some distance limit, and move the camera to follow the character if necessary. Supposing your character moves left/right in the x axis, you could do the following (camera script):

var target: Transform; //<- drag the character here in the Inspector
var limLeft: float = 5; // max left distance from the center
var limRight: float = 5; // min right distance from the center

function LateUpdate(){
  var posChar = target.position;
  var posCam = transform.position;
  if (posChar.x > posCam.x + limRight){
    transform.position.x = posChar.x - limRight;
  }
  else
  if (posChar.x < posCam.x - limLeft){
    transform.position.x = posChar.x + limLeft;
  }
}