- Home /
transform position of object in runtime
Hi, I'm trying to transform position of object in runtime, when I click on it, by this line
transform.position = new Vector3(20F,0F,0F);
or
transform.localPosition = new Vector3(transform.localScale.x,5.0F,transform.localScale.y);
I try with diferent parameters and every time object became transform in this same direction whatever I changed. For example
new Vector3(20F,0F,0F); new Vector3(0F,20F,0F); new Vector3(0F,0F,20F);
all these vectors creates the same action on my object.
I have also question how to transform the object to make it back to starting position.
Answer by alexanderameye · May 21, 2014 at 01:48 PM
I don't know about your first question (maybe try to be a bit more specific), but if you want to know how to set an original position, this should do it:
public class TPCamera : MonoBehaviour
{
Transform CurrentPos;
void Start()
{
CurrentPos = GameObject.transform;
}
}
Note: The gameobject is the gameobject you want to transform, so in the update(), you then can transform the object to 'CurrentPos', what is the original position. And also, if you want extra information about vector3, I recommend taking a look at this tutorial, and inside monodevelop, you could also select 'Vector3', and the press the CTRL-key and ' at the same time. Best of luck!
I dont know why I get this error: "An object reference is required to access non-static member `UnityEngine.GameObject.transform' unity"
Your answer
![](https://koobas.hobune.stream/wayback/20220613145543im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Tilt an object with arrowkeys 0 Answers
Skips off block when landing 0 Answers
'position' is not a member of 'UnityEngine.Vector3'. 1 Answer
Vector3.Slerp normal 1 Answer
Set the speed of an object by its distance with another object 1 Answer