- Home /
Question by
nadhirah88 · Sep 15, 2012 at 06:22 PM ·
transformbuttontranslateonmousedown
Transform translate
Hi!! I need help. I have one question. How to make one object(button) translate to other position when we click that object one time(function OnMouseDown), the object will translate to the other position. Then, we click the object again, then the object will return to the original position. Like push button.
Here are my scripts:
function OnMouseDown() {
// Move the object forward along its y axis
transform.Translate(0,0,-0.05);
audio.Play();
}
Thanks. :)
Comment
Answer by nestofexcess · Oct 20, 2013 at 09:22 PM
//declare this guy:
private float direction = -1f;
//what ever you gotta do
transform.Translate(Vector3(0,0,direction*0.05));
direction = direction * -1;