I know the command to destroy but it is not just like I want.
I made some breaking sprites that show how many durability of the tile is left. Like if it is small breaking sprite, you need to click 2 more times to break it. Or if it is big you need to click only 1 more time to break it. But when I try it, it is just not like I wanted.
I made a int that would count the times you click, and if it is 4, it would set the tile to null. But, it is for all of the tiles. I want to make the break count for each of the tile. Like, if you click a tile once, I want the small breaking sprite to stay there, and if you click another tile, I want it to break.
Pleae help
You don’t need to spam people please help.
I didn’t really understand. Do you mean like in minecraft?
?
It is not polite to spam several threads asking for help…
But to your question - you can’t store such data in Tilemap itself.
You can however create a matching table of positions (like a dictionary or a 2D array perhaps) that stores your classes containing information about each tile of your tilemap.
When you do digging or whatever it is, just check the position of hit, get tile data for that tile, and reduce some of its value you need to reduce. When tile value goes to zero, remove the visual tile from your Tilemap (it only serves as visual representation of your data).
You can of course alter the sprite of a tile at any given value… like have a breaking sequence (health is 3, show semi broken cracked block of stone).
See Unity’s tilemap extras I think they had something similar.
https://github.com/Unity-Technologies/2d-extras
I believe you can use prefab brush. Just make the same script for a cube, then make it prefab, then assign the sprites for it then break.
Thanks, it works, however, not like I wanted.
Hey, I am not really good at codes, can you create a small sample for me? So that I can figure out what is happening and fit it to mine.
Sorry, can’t / don’t have time. Besides, there are links and articles about this question - Just google for Unity forum threads and other articles. Like this one:
Well, please atleast copy the code and describe me their functions. I already checked this one and understood nothing at all.
Begging for someone else to do your work, or code begging is not part of this forum.
You’ll have to do your own learning - everybody has to. There is no shortcut… If you then have questions while creating your code - then ask, otherwise this is getting irritating.
Alright sorry, I think I am figuring things out a little bit. How do I change my mouse position into a grid position?
You could use the camera function, screentoworldpoint, with the input. Mouseposition to get the world position of mouse
Then use the tilemap worldtocell function to get the cellposition