- Home /
Question by
Lawar · Apr 11, 2015 at 10:02 AM ·
scripting problembutton
How to change buttons' positions
I have two buttons: one in the bottom-left corner and other in the bottom-right one. They have different pivots. And I need to change their positions via a script so that first button be on the position of second button and second button be on the position of the first one.
using UnityEngine;
using System.Collections;
public class ButtonSwitcher : MonoBehaviour
{
public GameObject step;
public GameObject jump;
Vector3 temp;
public void switcher()
{
temp = step.transform.position;
step.transform.position = jump.transform.position;
jump.transform.position = temp;
}
}
But the code above doesn't work correct. The buttons get out of the screen when I press a button to change their positions.
Comment
Take transform.position from button A and B, then assign the position of A to B and B to A.
If you need better instructions, show us your code.