Search Unity

2D camera position

Discussion in '2D' started by UnityMatt, Apr 21, 2015.

  1. UnityMatt

    UnityMatt

    Joined:
    Mar 7, 2015
    Posts:
    13
    I have a grid of tiles which are set up via script. When they come up on the scene the camera view is always on the center tile horizontally and vertically. I want it to start out in the upper left tile. the very first one in the grid.
    How can I do this?
     
  2. Sickwitit

    Sickwitit

    Joined:
    Dec 22, 2014
    Posts:
    123
    Just access the position of the element in your tile list that you wish to move your camera to.

    First get the objects you want to use.
    Next, pass in the new positions from the files you want to move the camera to.

    camera.transform.position = new Vector2(tiles[0].transform.position.x,tiles[0].transform.position.y);

    It depends on how you scripted your tiles. This is if they are stored in an array.
     
  3. UnityMatt

    UnityMatt

    Joined:
    Mar 7, 2015
    Posts:
    13
    Thanks,
    I got that to work, but I left something out. My tiles are in a Scroll Rect and have a Grid layout group and Constant size filter attached. So when I move camera pos it shifts all of that. So what I should have said is I want the very 1st tile to appear in the top left corner of the Scroll Rect. Would I have to alter each tiles pos once created or is there something in the scroll rect that I can use. It kind of needs to auto scroll to the top left corner, but I would rather it not scroll on its own, just start in that corner.
     
  4. UnityMatt

    UnityMatt

    Joined:
    Mar 7, 2015
    Posts:
    13
    I figured it out. You have to use the pivot. Changing to x=1 y =1 did it.
     
    Sickwitit likes this.