Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Tile Map How to scale (animate) individual tile at runtime ?

Discussion in '2D Experimental Preview' started by Aladine, Jan 6, 2019.

  1. Aladine

    Aladine

    Joined:
    Jul 31, 2013
    Posts:
    137
    Hi,

    Am making a simple match3 game, with tile swapping ability, so far everything works fine but i just want to add some juice to it, am wondering if i can have the Tiles shrink and grow up directly ?

    Am using this method to do the switching:

    Code (CSharp):
    1.  public void SwitchTiles(Tilemap _map, Vector3Int pos1, Vector3Int pos2)
    2.     {
    3.         //save selected Tile
    4.         TileBase selectedT = _map.GetTile(pos1);
    5.         //save target tile
    6.         TileBase targetT = _map.GetTile(pos2);
    7.         //place selected tile to the target position
    8.         _map.SetTile(pos2, selectedT);
    9.         //place target Tile to the selected position
    10.         _map.SetTile(pos1, targetT);
    11.     }
    Am wondering if there is a way to scale (and animate) an individual tile based on giving position ?

    I tried this :

    Code (CSharp):
    1. public void ScaleTileTest()
    2.     {
    3.         Tile t = _pointTile.GetTile(_testPos) as Tile;
    4.         t.gameObject.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
    5.     }
    but the casting from TileBase (GetTile()) to Tile didn't work.

    So far the only solution i can think of, is when doing the Switching, i'll hide the real tiles, instantiate Gameobjects to their positions, do the animation with these Gameobjects, and when its done, hide these objects and make the real tiles appear, but this feel like some useless extra work cause their must be a way to scale those tiles isn't ?

    thanks!
     
  2. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    99
    If the Tile is set on the Tilemap with a particular position, you could try the following to scale it on the Tilemap:

    Code (CSharp):
    1.  
    2. public void ScaleTile(Tilemap tilemap, Vector3Int position, Vector3 scale)
    3. {
    4.     var tileMatrix = tilemap.GetTransformMatrix(position);
    5.     var scaleMatrix = tileMatrix * Matrix4x4.Scale(scale);
    6.     tilemap.SetTransformMatrix(position, scaleMatrix);
    7. }
    8.  
    Unfortunately, to animate this, you may have to do this manually as the current Tile Animation does not support transform changes.
     
    Aladine likes this.