How can I save and load a player's position?

I'm designing a virtual navigation experiment, and i was wondering if i could somehow automatize my work. I need to present the same scene again and again, every presentation consists of adjusting player position first, than navigation, than if the subject says ready, save his position. So i thought about that maybe an algorithm could do it. The pure algorithm is something similar:

Load player position Let the player move the avatar Waiting for the subject to press ready Save position Do it again (approximately 20 times)

Could you help me out?

Agoston Torok, HAS, Institute of Psychology

Unity has a very simple built-in method of saving small amounts of data to the local machine using the PlayerPrefs class, which saves you from having to deal with explicitly reading and writing files. For example:

// to save an integer value
PlayerPrefs.SetInt("Player Score", 10);

// to retrieve the integer value
print (PlayerPrefs.GetInt("Player Score"));

And the commands are very similar for floats and strings:

PlayerPrefs.SetFloat("Player Lap Time", 29.3);
print (PlayerPrefs.GetFloat("Player Lap Time"));

PlayerPrefs.SetString("Player Name", "Duck");   
print ("Welcome back, " + PlayerPrefs.GetString("Player Name") + "!");

You could use this to write the x,y,z values of the player position and rotation.

You can also query the player prefs data to see whether a certain key has been set, using PlayerPrefs.HasKey, and delete keys using either PlayerPrefs.DeleteKey or PlayerPrefs.DeleteAll.

Sounds very similar to my work (also psychology with focus on navigation). I load and save all my data from text files using streamwriter link.

Should look something like this.

function Update () {

if (Input.GetButtonDown ("Fire1"))
 {
  var fileName : String;

  fileName = "C:\	est.txt";

  var stream = System.IO.StreamWriter(fileName);

  stream.WriteLine("test");
  stream.Close();

 }
}

Load and save your positions in a textfile. So basically, load player position, set his transform accordingly, enable him walking through the environment and when he clicks or reaches his destination, just save and repeat the whole process. If you need more details, I am basically doing something very similar.

Drop me an email with what you do for your research (sebastian DOT koenig AT canterbury DOT ac DOT nz).

Thanks to you I'm using the streamwriter, hope that this would work. And as you mentioned i prefer text files as output for further statistics, so the PlayerPrefs wouldn't be enough. I feel, that it needs some hours/days to finish it, but i will inform you about the progress os success. Thank you all!

Agoston Torok

Problem solved, it's working very well. Thank you very much!

This is probably a dead thread but I just started in on using Unity for my experiments and wanted to talk to a few fellow psychologists about their experiences.

I just finished working up a reaction time experiment I'll be implementing on the iPad and am concerned about the accuracy of the times that are generated. I did a very VERY low tech check by comparing the Unity generated times with those of a stopwatch and the times seemed to check out. Specifically, the events in Unity and the stopwatch were started at about the same time and basically matched (assuming that the .04 second difference was due to human error in the synchronization). What are your experiences with RT? Feel free to contact me at dgs45 AT drexel DOT edu