Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Animate square outline around a tile

Discussion in '2D' started by connorconway3, Apr 18, 2021.

  1. connorconway3

    connorconway3

    Joined:
    Mar 3, 2021
    Posts:
    3
    Hello all,

    I have a 2D top-down level and when you click a tile it displays an image outline to show that the tile has been clicked. Like the following:

    upload_2021-4-18_17-50-39.png

    At the moment I am just disabling and enabling the outline (Which is an image) when a tile is clicked.
    I would like to animate a dotted line around the tile that is clicked. How could I go around doing this as I'm too overwhelmed with all the options.

    Thank you for any help you can give :)
     
  2. Derekloffin

    Derekloffin

    Joined:
    Mar 14, 2018
    Posts:
    322
    Me personally, I'd just use a sprite game object that overlays the tilemap at the correct position. You can get the correct positioning info from the grid object of your tilemap, and this allows you to keep a single game object as your 'highlight' which you can simply move around where ever it is needed, having whatever effects/animations and rules you want on it independent of the tilemap itself.
     
  3. connorconway3

    connorconway3

    Joined:
    Mar 3, 2021
    Posts:
    3
    Thank you for your response Derek.

    What you have described is actually exactly how I have implemented it currently. That white outline you see over one of the cells is just a sprite overlay at the clicked position. When a cell is clicked, the white overlay appears and the panel to the right appears with actions on that type of tile.

    I am looking to extend this and have this square outline animated. I'm at a stage where I am looking to polish some of the UI up and looking at animations. I am also wanting to animate a line from the enemy portal to the spaceship (This is a tower defence game, and the enemies find a path using Breadth First Search but the player currently can't visualise the path that the enemies will take) and hoping that starting with this square animation will aid my understanding in that.

    Something similar to this is what I am trying to describe:
    https://www.vecteezy.com/video/1791446-abstract-light-stroke-square-animation
     
  4. FarmerInATechStack

    FarmerInATechStack

    Joined:
    Dec 28, 2020
    Posts:
    54
    Did you ever find a solution here?