• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Dried09 · Jan 06, 2018 at 03:14 PM · 2d

Tiles customization, additional data and functions (Tilemaps)

Hi there! Working now on 2d top down project (nes's battlecity-like) and decided to using useful new feature - Tilemaps from 2017.2 update. Everything was going well, but I'm stucked with implement destructuble tiles. I mean not just removing tiles from tilemap (I'm ok with it), I need to store durability value of each wall tile, which may be various depending on the wall material. And also I need additional functions to control durability, tile destruction and fx (dust particles, sounds). On the whole, I need all these useful possibilities that gives me a regular GameObject. But I know that tiles don't inherit MonoBehaviour class and I can't using it so.


What I alredy tried: 1) creating custom tile class by inherit Tile class and add necessary variables and functions.

 using System.Collections;
     using System.Collections.Generic;
     using UnityEngine;
     using UnityEngine.Tilemaps;
     using UnityEditor;
      
     public class DestructableTile : Tile {
      
         [SerializeField]
         public Sprite destructedTile;
      
         [SerializeField]
         public int durability = 3;
      
         /*
         public override void RefreshTile(Vector3Int location, ITilemap tileMap)
         {
             base.RefreshTile (location, tileMap);
         }*/
      
         public override void GetTileData(Vector3Int location, ITilemap tileMap, ref TileData tileData)
         {
             base.GetTileData (location, tileMap, ref tileData);
             if (durability <= 0)
             {
                 tileData.sprite = destructedTile;
                 tileData.colliderType = ColliderType.None;
                 //RefreshTile (location, tileMap);
             }
         }
      
         public void Damage()
         {
             durability -= 1;
             Debug.Log ("Durability is now: " + durability);
         }
      
         #if UNITY_EDITOR
         [MenuItem("Assets/Create/Destructable Tile")]
         public static void CreateAnimatedTile()
         {
             string path = EditorUtility.SaveFilePanelInProject("Save Destructable Tile", "New Destructable Tile", "asset", "Save Destructable Tile", "Assets");
             if (path == "")
                 return;
      
             AssetDatabase.CreateAsset(ScriptableObject.CreateInstance<DestructableTile>(), path);
         }
         #endif
     }

It takes effect even in editor mode and even on tile palette window! Also it doesn't refresh itself, and when I force refresh (commented code) - Unity editor is deadly freezes. Fail.

2) creating custom tile class by inherit TileBase class. I think rewriting all default functional for few small additions it's too much. Also fail.

3) seems like tiles data storing in tilemap's variable TileData, which is a struct. I can't find a way how to customize it, structs is not able to inherit other structs...

4) downloaded a 2d-extras assets from here https://github.com/Unity-Technologies/2d-extras Among other it contains GridInformation script, I guess it may be solution of my problem, but it has no any comments\docs\references about how to use it. Only info, which say's that script "stores and provides information".

Can someone help me?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

142 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Assets/Scripts/PlayerController.cs(32,49): error CS0126: An object of a type convertible to `float' is required for the return statement 1 Answer

2D Animation does not start 1 Answer

Problem of gravity 1 Answer

Dynamic Shader to Outline Adjacent Textures? 0 Answers

CharacterController or Collider/Rigidbody 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges