Hello Guest

Author Topic: Problem with OnTriggerEnter and Tilemap  (Read 4544 times)

Aldwin

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 6
    • View Profile
Problem with OnTriggerEnter and Tilemap
« 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 :
Code: [Select]
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.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Problem with OnTriggerEnter and Tilemap
« Reply #1 on: April 03, 2013, 10:54:58 pm »
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();
}

Aldwin

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Problem with OnTriggerEnter and Tilemap
« Reply #2 on: April 04, 2013, 07:45:07 am »
It works, thanks a lot !