I want to make a script to put a gameObject to the start position it had when it entered the scene when I click a button in unity
CodePudding user response:
Save the initial position and call the return code to the first location via the following steps:
public Vector3 basePosition; // save the initial position
private void Start() => basePosition = transform.position;
public void ReturnBack() => transform.position = basePosition;
CodePudding user response:
You can't. A GameObject cannot be transformed into a Transform. However, each GameObject has access to its own Transform: gameObject.transform
CodePudding user response:
Just declare a "Vector3" variable and then you use the "gameObject.transform.position =" and then the name of the variable you've created.
var new_position = Vector3(0, 0, 0);
gameObject.transform.position = new_position;