I have a button that moves in from right to its target position - script below. What I tried and couldn’t do is to:
Move the button in when I click on a button (another button) rather than on start. How should I go about doing that?
var target = 100.0;
var move = 200;
function Update () {
move = Mathf.Lerp(target + 100, target , Time.time);
}
function OnGUI () {
GUI.Button(Rect(move, 100.0, 100.0, 50.0), "Moving Button!");
}
Assuming you want to keep your move calculations in your Update() function, try this:
var target = 100.0;
var move = 200;
private var moving : boolean = false;
private var clicktime : float;
function Update () {
if(moving){
move = Mathf.Lerp(target + 100, target , Time.time-clicktime);
}
}
function OnGUI () {
if(GUI.Button(Rect(//where you want the other button), "Make the button move!") && !moving){
clicktime = time.time;
moving = true;
}
GUI.Button(Rect(move, 100.0, 100.0, 50.0), "Moving Button!");
}
You will need to change the ‘//where you want the other button’ to a real rect, of course.