- Home /
Generate Tiles Programatically Over Player Position?
I'm working on a basic 2D top-down game using Unity and have a player sprite that I move using the directional arrow keys.
This player sprite (a unicorn) is on a tilemap.
How do I generate tiles (rainbow tile) where ever my unicorn moves along the tilemap?
I read the manual from Unity saying that there's a Tile class that I can use to do it: https://docs.unity3d.com/Manual/Tilemap-ScriptableTiles-Tile.html but I'm still a bit perplexed on how to actually implement it.
I have a Player Collision script that goes:
public class UnicornCollision : MonoBehaviour {
public void OnTriggerEnter2D(Collider2D other){
if (other.gameObject.tag.Equals("SpaceTile")
{
Debug.Log("You're on a space tile");
// Insert code to generate rainbow tiles here.
}
else if (other.gameObject.tag.Equals("GrassTile")
{
Debug.Log("You're on a grass tile");
}
}
}
And I have 2 tilemaps each tagged with "SpaceTile" or "GrassTile" as well as each having a Tilemap Collider 2D to detect collision on trigger.
My unicorn sprite (player) has a Rigidbody 2D and Polygon Collider 2D components.
Your answer
Follow this Question
Related Questions
Pixels per unit with tile palette? 1 Answer
Problems with 2D Collision 3 Answers
Sprite collision with Tilemap 2 Answers
Sprite Collision with Tilemap with 3D Colliders? And would just using 3D walls be as good or worse? 0 Answers
Blur 2d Sprite 0 Answers