title: Detect if "player" is left or right of the middle of screen
body: <p>Hello and thanks for reading this.</p>
  
  <p>I'm fairly new to unity but regardless of that fact I made a little game, same stile as mario and other. A game were you Move left and right and jump to avoid enemy.</p>
  
  <p>But I face a little code problem and I cant seem to find a answer anyway to help me solve it.</p>
  
  <p>I need to detect if player left or right of the middle of screen, so I know if the camera have to move left or right.</p>
  
  <p>This is the camera script I'm so far created.</p>
  
  <pre><code>using UnityEngine;
  using System.Collections;
  
  public class CameraFunction : MonoBehaviour {
  
  float ydir = 0f;
  public GameObject player;
  //for our GUIText object and our score
  public GUIElement gui;
  float playerScore = 0;
  
  //this function updates our guitext object
  void OnGUI(){
      gui.guiText.text = "Score: " + ((int)(playerScore * 10)).ToString ();
  }
  //this is generic function we can call to increase the score by an amount
  public void increaseScore(int amount){
      playerScore += amount;
  }
  //Camera will be disabled when we load a level, set the score in playerprefs
  void OnDisable(){
      PlayerPrefs.SetInt ("Score",(int)(playerScore));
  }
  
  // Update is called once per frame
  void Update () {
      //check that player exists and then proceed. otherwise we get an error when player dies
      if (player) {
  
  
          if (player.transform.position.x &gt; -1) {
  
              //update our score every tick of the clock
              playerScore += Time.deltaTime;
  
              transform.position = new Vector3 (transform.position.x + 0.03f, transform.position.y, -10);
          }
      }
  }
  }
  </code></pre>
  
  <p>My script only detects if the "player" pass the middle of the current view and then start moving.</p>
  
  <p>I hope you understand what I mean, and will be able to help me.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>If you look at it this way, we can split the screen in 2, the left and right part, and ofcourse we have the middle between those 2. </p>
  
  <p>The person/player starts on the left side of the screen and have to move right throught the map to the end goal. </p>
  
  <p>Right now when the person pass the middle and into the right of the screen the camera will start moving right. But I can't make it detect if the user/player moves backwards then he camera have to "freeze".</p>
  
  <p>So if player position is > 50% of screen(Right side) = Camera move right.
  If player position is &lt; 50% of screen(Left side) = Camera "Freeze". </p>