Advertisement
Guest User

Untitled

a guest
Oct 15th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class SaveLocation : MonoBehaviour {
  6.  
  7.     //position
  8.     public float thisCharactersXposition;
  9.     public float thisCharactersYposition;
  10.     public float thisCharactersZposition;
  11.  
  12.     //rotation
  13.     public float thisCharactersXrotation;
  14.     public float thisCharactersYrotation;
  15.     public float thisCharactersZrotation;
  16.  
  17.     public void Awake(){
  18.  
  19.         thisCharactersXposition = PlayerPrefs.GetFloat ("MyPositionX");
  20.         thisCharactersYposition = PlayerPrefs.GetFloat ("MyPositionY");
  21.         thisCharactersZposition = PlayerPrefs.GetFloat ("MyPositionZ");
  22.  
  23.         thisCharactersXrotation = PlayerPrefs.GetFloat ("MyRotationX");
  24.         thisCharactersYrotation = PlayerPrefs.GetFloat ("MyRotationY");
  25.         thisCharactersZrotation = PlayerPrefs.GetFloat ("MyRotationZ");
  26.  
  27.     }
  28.  
  29.  
  30.     // Use this for initialization
  31.     public void Start () {
  32.         transform.position = new Vector3 (thisCharactersXposition, thisCharactersYposition, thisCharactersZposition);
  33.         transform.rotation = Quaternion.Euler (thisCharactersXrotation, thisCharactersYrotation, thisCharactersZrotation);
  34.     }
  35.  
  36.     // Update is called once per frame
  37.     public void Update () {
  38.         PlayerPrefs.SetFloat ("MyPositionX", transform.position.x);
  39.         PlayerPrefs.SetFloat ("MyPositionY", transform.position.y);
  40.         PlayerPrefs.SetFloat ("MyPositionZ", transform.position.z);
  41.  
  42.         PlayerPrefs.SetFloat ("MyRotationX", transform.eulerAngles.x);
  43.         PlayerPrefs.SetFloat ("MyRotationY", transform.eulerAngles.y);
  44.         PlayerPrefs.SetFloat ("MyRotationZ", transform.eulerAngles.z);
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement