2D Toolkit Forum
2D Toolkit => Support => Topic started by: Aldwin on April 03, 2013, 07:22:04 pm
-
Hi,
sorry, maybe it's a basic question but I'm not really a coder so I can't understand how to do :
I'm working with a tilemap and I want some bullets shot by the player to trigger when they entering any tilemap collision. I put a trigger on my bullets and the triggering works well (I check it with other colliders) but my problem is that I don't know how to "define" the tilemap. I found that the bullet triggers the collision with a chunk of the tilemap, but it seems very complicate to make a loop to check every chunks.
Here my code in the bullet script :
void OnTriggerEnter(Collider enteringCollider)
{
if (/*enteringCollider is a tilemap collider <-- this is here I don't know how to do*/)
{
Debug.Log("bullet touch map");
isDead = true;
}
Sorry for my english too, I'm french, and thanks for your answers.
-
You can use layers for this.
Create a new layer in Unity.
Assign this to all your tilemap layers (or just the ones you care about) in Settings > Layers. Basically that thing that says "Default", change it to the layer you created.
Now in the trigger stuff, you can do things like
if (enteringcollider.gameObejct.layer == tilemapLayerNumber) {
DoSomething();
}
-
It works, thanks a lot !