Search Unity

2D Camera Problem

Discussion in '2D' started by TTaspar, Feb 10, 2016.

  1. TTaspar

    TTaspar

    Joined:
    Feb 10, 2016
    Posts:
    6
    hello everyone
    i made infinite road . i have character and camera follows him . But i dont want camera to go back . Camera just go +x , not -x .

    example :
    □ think , this square is my cam view . □ → and i want camera to go +x . okey ? just +x !!! i dont want
    -x . How can i do that ? please help me ..... (sory about my english . im not good at english :) )
     
  2. KrayZLogic

    KrayZLogic

    Joined:
    Jun 19, 2013
    Posts:
    55
    Create a script and attach it to the camera object. Make sure the camera object is not a child of the character object.

    Code (CSharp):
    1. public Transform m_Character;
    2.  
    3. void Update ()
    4. {
    5.     if (m_Character.position.x > transform.position.x)
    6.         transform.position = new Vector3 (m_Character.position.x, yPosition, zPosition);
    7. }

    In the inspector, attach your character object to the m_Character variable.
     
    TTaspar likes this.
  3. TTaspar

    TTaspar

    Joined:
    Feb 10, 2016
    Posts:
    6
    Thank u for ur response and ur help :):)