x


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?

more ▼

asked Apr 04 '11 at 11:07 PM

austen 2 gravatar image

austen 2
1 4 4 8

(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3444
x436
x294
x12

asked: Apr 04 '11 at 11:07 PM

Seen: 678 times

Last Updated: Apr 04 '11 at 11:12 PM