how to move the literal button when clicked

Im currently making a word game so my button when clicked would go upwards to the blank and when it’s clicked again it will go back to it’s original position (not clicked)
(


(clicked)

and i dont know how to move the button :slight_smile:

Since they are buttons, use a tweening engine such as LeanTween or Dotween(both are free on the asset store). I use LeanTween myself and they have a variety of simple calls you can do to animate to positions. They seem especially well suited for moving UI components (but can do other stuff).

So basically with one of these, you’ll click the button, run the tween on it to move it up, or click and move it down (some check to determine which direction to go).

To move a button can’t you use something like Transform.translate?

Of course you can use standard unity stuff. But tweening engines make it super simple and good tweening engines don’t really add much to the project. The benefits are worth it. Especially since you can do something like have a piece move and then when it’s finished moving you can call a method oncomplete to run code, or you can do an onupdate call to do something while it’s moving.

Oh nice! I’ve never used tweening engines so I’ll have to check them out myself lol

Thank you very much but what if i use transform.Translate tho how should i do it

ublic class MOve : MonoBehaviour {
     private Button button1;
    // Use this for initialization
    void Start () {
        button1 = GetComponent<Button>();
    }
   
    // Update is called once per frame
    void Update () {
      
         
        }
    void moveup()
    {
        if (Input.GetMouseButtonDown(0))
        { button1.transform.Translate(131, 22, 0); }
    }

    }

this is my code

how do i do it?
im just asking so i know how to do it in both ways
and do you know any tutorials on DOTWEEN?

transform.translate requires you to basically have it move in a direction. To get it to go to a particular spot, you’ll have to do some math and figure out what direction you need to go and how to get it there, plus doing checks for when it gets there so it stops moving. Honestly, for this situation, it’s more trouble to use then it’s worth.

The reason I suggest a tween is you don’t have to do that. You set a start position, an end position, and the time you want it to take to get there. Plus, once it’s there, you can do a complete call to execute some code if you want it to do something else.

Chances are, what you really want if you don’t plan to use a tweening engine is to use Lerp. Vector3.Lerp allows you to declare a start and end position and lets you declare a number from 0-1 to determine where in the path it is. So at .5 it would be halfway to the end position. You’ll have to increment this number gradually depending on how fast you want something to move. (The tween engine will handle this for you, you just tell it how quickly you want the object to move. You can also add cool effects like bounce and such if you wanted)

As far as Dotween, I’ve never used it. They seem to have some examples on their site DOTween - Examples, plus I’m sure there are some youtube videos on it as well. I use LeanTween currently as it was the one we use at work and it’s one of the better ones. Dotween is also really good I’ve heard, but I stuck with the tween that I had already been using at work.

can i use leantween or dotween in 2d?

and how to i make it move when i click it?

To find tutorials, there are amazing tools out there.
My favorites:
Bing.com
Google.com
YouTube.com

Just in less than a minute I found this:
https://www.youtube.com/watch?v=XCV7OmgwwQw

YouTube is a great place for Unity3D tutorials.

As for using Transform.Translate, you’ll need to look here in the (mostly self-explanatory) docs: http://docs.unity3d.com/ScriptReference/Transform.Translate.html

leantween and dotween both work on 2d and 3d. It’s not going to fit every scenario (like where you want your player to control the movement of a char), but if you are doing movements, color changes, scaling, etc, they are pretty amazing.