Search Unity

looking to pan camera around guitexture background

Discussion in 'Scripting' started by deiong, Aug 1, 2014.

  1. deiong

    deiong

    Joined:
    May 24, 2013
    Posts:
    79
    i have a guitexture as a background for 2d, and am looking to pan around a 4096x4096 image background with the camera set to 1024x768. I tried to add a script to the background but haven't had success

    void OnMouseDown () {

    Debug.Log(pos);

    // min{x=0 y=-4.333} max{x=-3 y=0} x= * 0.000732421875 y= * 0.001057861328125


    neither work below :(

    pos.x = Mathf.Clamp(Input.mousePosition.normalized.x, 0, -3);
    pos.y = Mathf.Clamp(Input.mousePosition.normalized.y, -4.333f, 0);

    pos.x = Input.mousePosition.x * 0.000732421875f;
    pos.y = Input.mousePosition.y * 0.001057861328125f;


    transform.position = pos;

    }

    any ideas. I want to keep in bounds of the background.
     
  2. hammil

    hammil

    Joined:
    Jun 5, 2013
    Posts:
    56
    This is a bit too complex for me to develop something myself, but I will suggest that you use the raw mouse input to 'move' the camera, rather than just setting the position each time.
     
  3. deiong

    deiong

    Joined:
    May 24, 2013
    Posts:
    79