Hi! I am currently creating an in-game editor and trying to display the current position (X, Y, Z) of an object in three text fields until you edit the text. If you then press Enter, the position is automatically set to the entered number (as in the Unity Inspector). Unfortunately, I don’t know how to do it. Can someone help me?
I think you would be better off using a Vector3. Its meant for storing 3d information, such as position, scale, rotation, velocity, etc.
I would do something like this:
public Vector3 position;
void Update()
{
//Finds out if the enter key is pressed
if(Input.GetButtonDown("Enter")
{
//Sets the object's position this script is attached to, the var position.
transform.position = position;
}
}
I think this should work, but there may be a typo because I’m working on it in the browser.
Another way to go about it, that would display the position in that variable would be this:
public Vector3 position;
public bool editing = false;
void Update()
{
if(editing)
{
//Changes the Object's position to the position var
transform.position = position;
}
if(!editing)
{
//Changes the position var to the object's position
position = transform.position;
}
}