C# ONLY PLEASE
I am using player prefs to save my players position but I am getting these errors:
Assets/PosSave.cs(16,42): error CS1612: Cannot modify a value type return value of `UnityEngine.Transform.position’. Consider storing the value in a temporary variable
Assets/PosSave.cs(17,42): error CS1612: Cannot modify a value type return value of `UnityEngine.Transform.position’. Consider storing the value in a temporary variable
Assets/PosSave.cs(18,42): error CS1612: Cannot modify a value type return value of `UnityEngine.Transform.position’. Consider storing the value in a temporary variable
I
do not know how to fix these
Here is my script
using UnityEngine;
using System.Collections;
public class PosSave : MonoBehaviour {
public GameObject player;
public float x;
public float y;
public float z;
// Use this for initialization
void Start () {
if (PlayerPrefs.HasKey ("x") && PlayerPrefs.HasKey ("y") && PlayerPrefs.HasKey ("z")) {
x = PlayerPrefs.GetFloat("x");
y = PlayerPrefs.GetFloat("y");
z = PlayerPrefs.GetFloat("z");
player.transform.position.x = x;
player.transform.position.y = y;
player.transform.position.z = z;
}
}
// Update is called once per frame
void Update () {
x = player.transform.position.x;
PlayerPrefs.SetFloat("x", x);
y = player.transform.position.y;
PlayerPrefs.SetFloat("y", y);
z = player.transform.position.z;
PlayerPrefs.SetFloat("z", z);
}
}