- Home /
Help with Saving ArrayPrefs
im using the arrayprefs script from http://www.unifycommunity.com/wiki/index.php?title=ArrayPrefs.
Im trying to save the positions of instantiated cubes. I add each cube to an array when instantiated and give the cube a unique name so i can save the Vector3 of each cube. Here is my script.
static var cubes = new Array(); var cubeCount = 0; function Update() { if (Input.GetMouseButtonDown(0)) {
var go = Instantiate(cube2, transform.position, Quaternion.identity) as GameObject;
go.name = "cube"+cubeCount;
cubes.Add("cube"+cubeCount);
cubeCount++;
}
if(Input.GetKey("m")) { saveGame(); Debug.Log("saved"); }
}
function saveGame() {
for (i=0 ; i < cubes.length - 1 ; i++)
{
curName = cubes[i];
PlayerPrefsX.SetVector3( curName, curName.transform.position);
}
Im getting a NullReferenceException: Object reference not set to an instance of an object on the (PlayerPrefsX.SetVector3( curName, curName.transform.position);) line.The array is working and naming itself correctly but i keep getting that error. is my logic wrong? is there an easier way to do this?
Your answer
Follow this Question
Related Questions
How to save an array to PlayerPrefs? 1 Answer
playerprefs problem 0 Answers
PlayerPrefs not working for different scenes 1 Answer