- Home /
Get the Vector position of the player object when clicking another object C#
I have a player object and I want to grab that vector position when I click on another object. The other object will load a mini game and a new scene will open. I want to be able to go back to that position when the mini game is completed. Right now it is just reloading the original scene so the player isnt where he was when the item is clicked. Im doing this in C# and have been having issues with parsing and whatnot. Any help is appreciated.
Answer by Alec-Slayden · May 04, 2011 at 05:01 PM
Some of this may be answered by This Question and answers involving scene loading, DontDestroyOnLoad, and static variables.
You can create an empty game object with a script that has called DontDestroyOnLoad in the Awake function, and declared a static var to hold the position.
To actually acquire your player object position, you can set a public transform variable in whatever script actually loads the next scene, and drag your player object to that variable in the inspector.
In that loading script, just before you load a scene, you can store the player position in the static var, which will persist as you load scenes.
Your answer
Follow this Question
Related Questions
Reverse Look up ( have transform want the gameObject of that transform) 2 Answers
static gameobject 1 Answer
unknown axis of rotation 1 Answer