I’m using this code to adjust an object’s position while the right mouse button is held down
if(Input.GetMouseButtonDown(1)){
transform.Translate (1,2,1);
}
How would I revert its position when the button is released?
I’m using this code to adjust an object’s position while the right mouse button is held down
if(Input.GetMouseButtonDown(1)){
transform.Translate (1,2,1);
}
How would I revert its position when the button is released?
Vector3 primaryPosition;
void Start(){
primaryPosition = transform.position;
}
void Update(){
//btw GetMouseButtonDown(1) only recieves the first click. If you want to detect continuously use GetMouseButton(1) instead
if (Input.GetMouseButtonDown(1)){
transform.Translate (1,2,1);
} else if (Input.GetMouseButtonUp(1)){
transform.position = primaryPosition;
}
}