- Home /
How to set the position of an object using variables.
I thought that this would be a simple task. When you hit left shift your x and y position is recoded because I am making a 2.5D game. Then if you hit left CTRL you should teleport back to where you hit shift. However I can not get it to work here is the code:
function Update () {
if( Input.GetButtonDown("Fire1")){
var playerX = transform.position.x;
var playerY = transform.position.y;
var playerRotation = transform.rotation;
print("X = "+playerX);
print("Y = "+playerY);
print("Rotation = "+transform.rotation);
}
if(Input.GetButtonDown("Fire2")){
transform.position = new Vector3(3,0,0); transform.rotation = playerRotation;
}
}
Answer by FlyingOstriche · Oct 22, 2012 at 08:35 PM
var storePosition:Vector3;
var storeRotation:Quaternion;
function Update () {
if( Input.GetButtonDown("Fire1")){
storePosition=transform.position;
storeRotation=transform.rotation;
}
if( Input.GetButtonDown("Fire2")){
transform.position=storePosition;
transform.rotation=storeRotation;
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613082739im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Accessing variables from different scripts. 3 Answers
GUI will not disappear 1 Answer
platforme ...HELP!! POSITION ADDING 1 Answer
Grid Systems 0 Answers