Player Prefs saving position Script assistance.

I’ve been working on this script for 3 days and am finally asking for assistance. I’ve managed to save Int’s using PlayerPrefs, but can’t get my positioning right. I’ve used answers found here and the script reference to put this together.

I’d like assistance rewriting this, and adding vector3 to save and load for my character.

Here’s the parts of the script throwing errors:

//-----Players Position----------

var PlayerX : float;

var PlayerY : float;

var PlayerZ : float;

var PlayerPosition : Transform;

var player : GameObject;

function Update(){

//=======Setting Player position for save====

PlayerX =(PlayerPosition.transform.position.x);

PlayerY =(PlayerPosition.transform.position.y);

PlayerZ =(PlayerPosition.transform.position.z);

}

//saving playerPrefs

function saveAttributes()
{

PlayerPrefs.SetFloat("PlayerX");
PlayerPrefs.SetFloat("PlayerY");
PlayerPrefs.SetFloat("PlayerZ");

}

function loadstuff () {

PlayerX = PlayerPrefs.GetFloat("PlayerX");
PlayerY = PlayerPrefs.GetFloat("PlayerY");
PlayerZ = PlayerPrefs.GetFloat("PlayerZ");

PlayerPosition.transform.position.x = ("PlayerX");
PlayerPosition.transform.position.y = ("PlayerY");
PlayerPosition.transform.position.z = ("PlayerZ");
player.transform.position = ("PlayerPosition");

}

Here are the errors:

BCE0017: The best overload for the method ‘UnityEngine.PlayerPrefs.SetFloat(String, float)’ is not compatible with the argument list ‘(String)’.

BCE0022: Cannot convert ‘String’ to ‘float’.

I wouldn’t mind converting this to use arrayPrefs, but I need help writing it versus a link to the script reference, or wiki. I’ve managed to learn from veiwing examples here on Answers this much through a diligent search and try method.

Any assistance would be most appreciated, thank you.

//=======Setting Player position for save====

PlayerX =(PlayerPosition.transform.position.x); PlayerY =(PlayerPosition.transform.position.y); PlayerZ =(PlayerPosition.transform.position.z);

} //saving playerPrefs function saveAttributes() {

PlayerPrefs.SetFloat("PlayerX");
PlayerPrefs.SetFloat("PlayerY");
PlayerPrefs.SetFloat("PlayerZ");
}

you are not saving the values here. SetFloat will take a string and a value. the one you have entered is a string that identifies the value to be followed.
it should be like.

{
   PlayerPrefs.SetFloat("PlayerX",PlayerX);
   PlayerPrefs.SetFloat("PlayerY",PlayerY);
   PlayerPrefs.SetFloat("PlayerZ",PlayerZ);
}

also refer scripting refernce for this function

I got it to work. Many thanks for the assist. I’m going to post my updated version here for others to use as many of the answers to similar questions I find too vague.

private var PlayerX : float;

private var PlayerY : float;

private var PlayerZ : float;

var PlayerPosition : Transform;

var player : GameObject;

function Update(){

//=======Setting Player position for save====

PlayerX =(PlayerPosition.transform.position.x);

PlayerY =(PlayerPosition.transform.position.y);

PlayerZ =(PlayerPosition.transform.position.z);

//=====Press "K" key to save position.================

if (Input.GetKeyUp ("k")){

 saveAttributes();
 
 }

//=====Press "L" key to load position.================

if (Input.GetKeyUp ("l")){

 loadstuff();
 
 }


}

//saving playerPrefs

function saveAttributes() {

PlayerPrefs.SetFloat("PlayerX",PlayerPosition.transform.position.x);
 
PlayerPrefs.SetFloat("PlayerY",PlayerPosition.transform.position.y);
 
PlayerPrefs.SetFloat("PlayerZ",PlayerPosition.transform.position.z);

}

function loadstuff () {


PlayerPosition.transform.position.x = (PlayerPrefs.GetFloat("PlayerX"));

PlayerPosition.transform.position.y = (PlayerPrefs.GetFloat("PlayerY"));

PlayerPosition.transform.position.z = (PlayerPrefs.GetFloat("PlayerZ"));

}