- Home /
store character position
How can I store a character's position, then later have the character start from that position?
You have to be more specific on how you want to store this information and how you are going to use it later. You might want to store in a file or just in the same session of the game.
Answer by Ashkan_gc · Mar 04, 2010 at 08:17 PM
what do you mean by storing. do you want to store it for later sessions of the game? if yes you should use PlayerPrefs and SetFloat method to store all transform.position.x and .y and .z and then read them by GetFloat method. if you want to store them for later use during current game session just put them in a static vector3. create something like
static Vector3 initialpos;
then write yourclassname.initialpos = transform.position; and read it back. also if you don't want to use static variables just create a GameObject and use DontDestroyOnLoad and add a component for storing positions to it.
Answer by Eric5h5 · Mar 04, 2010 at 08:14 PM
Use PlayerPrefs.SetFloat to store the x, y, and z components of the character's position, and then PlayerPrefs.GetFloat to read it in again. Also you probably want to save the rotation or eulerAngles.
Your answer
Follow this Question
Related Questions
Character Positions Not Serializing or Loading Properly? 1 Answer
Save and restore object transform in editor 0 Answers
How to save players position then load a level (pause menu) 2 Answers
How can I save MouseLook position in this script ? 0 Answers
how to make Items get close to character like magnet? 1 Answer