- Home /
Getting and sending a gameobjects position to another gameobject.
Hello, I want to pass the position and rotation from one game object A to another game object B (which is not destroyed on load) for storage and then pass back that value to object A when the level is loaded.
I have tried to store it as a transform.position with a vector 3 and as Transform.
how do I get the position of gameobject A
I tried public Vector3 coordinates; coordinates = gameobjectA.getcomponent().transform.position;
and I tried
public Transform LastPosition; LastPosition=gameobjectA.getcomponent.Transform with no luck returned a null exception.
please ignore the typos i am writing this away a pc without monodevelop.
How would you get the position of game objectA to gameobjectsB script? is there a way to get rotation and potition? (is there a way to store transform?)
Many thanks, Dimitris.
Answer by SarperS · May 08, 2012 at 12:53 PM
You can hold it in a static variable so it will be persistent and hold the value even though the scenes change.
The syntax is incorrect on both lines you've written. It go like this;
static public Vector3 pos;
pos = a.transform.position; //Or a.GetComponent<Transform>().position with your way
Your answer
Follow this Question
Related Questions
Specifying an x coord problems 1 Answer
Why can't I get the transform from an instantiated object? 1 Answer
transform.position not setting position OR animation setting position even though it shouldn't 0 Answers
fixed distance for Vector3.moveTowards ? 1 Answer
Why can't I assign transform.position to a Vector3 object? 3 Answers