Search Unity

Need Help with Saving and Recalling Camera Position

Discussion in 'Scripting' started by w1nterl0ng, Feb 27, 2012.

  1. w1nterl0ng

    w1nterl0ng

    Joined:
    Jan 19, 2010
    Posts:
    32
    I am using the old MaxCamera mouse orbit zoom script.
    http://pastebin.com/rMVrwNyL

    I need be able to save a camera postion and recall it later.

    Would someone please take a look and help me out?

    Thanks.
     
  2. flaminghairball

    flaminghairball

    Joined:
    Jun 12, 2008
    Posts:
    868
  3. w1nterl0ng

    w1nterl0ng

    Joined:
    Jan 19, 2010
    Posts:
    32
    @FlamingHairball Thanks for the info. But I am having trouble getting the camera to actually respond to the settings. What are you putting in the prefs and how are you recalling it? My cam just stays where it is.
    Thanks.
     
  4. ohLogical

    ohLogical

    Joined:
    Feb 12, 2012
    Posts:
    98
    to save camera position on x axis
    Code (csharp):
    1. if(whatever you want to do to save {
    2.  
    3. PlayerPrefs.SetFloat("Camera Position X", 10.0);
    4. }
    to load camera position
    Code (csharp):
    1.  
    2. function Start () {
    3.  
    4. transform.position.x = PlayerPrefs.GetFloat("Camera Position X")
    5. }
    6.  

    Then do that for y, z, and the rotations.