- Home /
How I change position by button
Hello... How I change position of object in the form by button in another form through assignment the form of object?
Comment
How I change position of object in the form by button in another form
Don't understand the question. I'm guessing this means you have a button in one part of your interface and you want it to control the position of a button in another part of the same interface. Is this correct?
Answer by Addyarb · Nov 18, 2014 at 12:14 AM
If it were me, this is how I'd do it:
using UnityEngine;
using System.Collections;
public class MoveObjectWithButton : MonoBehaviour {
public Transform position1;
public Transform position2;
public Transform myObject;
// Use this for initialization
void Start () {
myObject.transform.position = position1.transform.position;
}
void OnGUI(){
if (GUI.Button (new Rect (10, 70, 50, 30), "Position 1")) {
myObject.transform.position = position1.transform.position;
}
if (GUI.Button (new Rect (10, 140, 50, 30), "Position 2")) {
myObject.transform.position = position2.transform.position;
}
}
}