Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Camera target block "x"

Discussion in 'Scripting' started by TechnoObi, Aug 21, 2014.

  1. TechnoObi

    TechnoObi

    Joined:
    Nov 30, 2013
    Posts:
    82
    I'm making a 2d game. In this my camera follows my player, but only in the "y" direction. If my character moves in the "x" direction, the camera should not follow my character. At the moment the "y" movement works, but how can I do it with "x"?
     
  2. Patico

    Patico

    Joined:
    May 21, 2013
    Posts:
    886
    You just should not change x position of your cam ;)
    Nobody can give you right advice without your code.
     
  3. konkon777

    konkon777

    Joined:
    Jul 24, 2014
    Posts:
    10
    if there is a code like this in your camera script. transform.position=target.position change it to transform.position.y=target.position.y thats all.
     
  4. Patico

    Patico

    Joined:
    May 21, 2013
    Posts:
    886
    It will work only with JS.
    In C# need to change whole vector:
    Code (csharp):
    1. transform.position= new Vector3(fixedXValue, target.position.y, target.position.z);