Search Unity

Question How can achieve this behavior as shown in the video. https://youtu.be/Yy-3Bd91fUI

Discussion in 'Scripting' started by unrealshadowx, Apr 11, 2021.

  1. unrealshadowx

    unrealshadowx

    Joined:
    Nov 2, 2018
    Posts:
    2
  2. Aladine

    Aladine

    Joined:
    Jul 31, 2013
    Posts:
    195
    You can create a simple object snapping tool that has 2 main components:

    * The SnapElement (the words)
    * The SnapHandler

    The SnapElement will have informations such as the length of the word, to know where it begins and where it should ends.

    The SnapHandler will have a list of these elements and place the, next to each other based on their orders in the list, and basically creating a 1D grid.

    Now for the element switching:

    * there are plenty of ressources to check how to do a drag and drop behavior, so just look that up, but i personally rather you do it with raycasting instead of using the built-in OnMouseDrag() method, but that is totally up to you

    but the behavior itself should be this:
    * Pick up an element (word) and make it follow mouse movement
    * Convert current element world position to the correspondent position of the grid.
    * When position change place the typing cursor in the new grid position
    * on release switch the picked up element with the grid position elements (switch them on your list too)

    Once you have that, you can use DoTween (the free version is enough) to animate the whole thing.

    Good luck