Hello Guys , I's like to implement a logic , that destroys a Tile , if the player hits it . I don't get the point , how I "connect" my Tilemap to the player Class . My Tilemap is not having its own Script . What is best practise ? Hope you can help me ! Thank You !
Theres an example of this in the Brickbreaker project here: https://github.com/Unity-Technologies/2d-techdemos Look at how the ball detects tiles and destroys them on collision. https://github.com/Unity-Technologies/2d-techdemos/blob/master/Assets/Tilemap/Brick/Scripts/Ball.cs
Thank you for awnsering . I have already check out this solution but dont understand it, and propably this is why its not working . He declares the tilemap attribute and later assigns a Tilemap to it , with GetComponent... . But why is Tilemap a Component of the GameObject ? I dont get the point , how its getting my createt Tilemap ? Code (CSharp): public GameObject tilemapGameObject; Tilemap tilemap; tilemap = tilemapGameObject.GetComponent<Tilemap>(); Sorry for not perfect English .
I assume they assign the GameObject "tilemapGameObject" in the inspector. That object contains the component Tilemap. They could have made the Tilemap type variable public, and assign it that way, but they decided to make it a GameObject and use GetComponent. If you only have one tilemap in the scene, you can try using this on Awake or Start: tilemap = FindObjectOfType<Tilemap>(); Please note that this function is expensive, and it's best not to use it if you can just assign it in the inspector.