I have a player character and would I like to press a button and disable the entire tilemap collider 2D. But I cant find a way to access the tilemap Collider?
The Tilemap Collider is a component like any other; you can disable it the same way you disable any other component. In the script below “platforms” is the tilemap the Tilemap Collider 2D is attached to:
using UnityEngine;
using UnityEngine.Tilemaps;
public class DisableCollider : MonoBehaviour
{
private TilemapCollider2D platforms;
private void Start()
{
platforms = GetComponent<TilemapCollider2D>();
}
private void Update ()
{
if (Input.GetKey(KeyCode.Space))
{
platforms.enabled = false;
}
}
}
Edit: I tested it in my own game; it’s working.
Ohhh, I forgot UnityEngine.Tilemaps
Thanks!
you are a life saver forgot to import tilemaps library
i know this is kinda old, but is there any way that i can deactivate like the tilemap collider on a whole layer? so i can switch between like layer one and layer two with some trigger zones
Please create your own threads rather than hijacking/necroing old ones.
Thanks.