Change transparency of the (entire) tilemap via script

Hello there, I want to build something like a cave in my platformer game with hidden entry. The player should hit the collider. After the collision, the “cave” should be visible as it is.
My question is now, is there a more simple way to change the transparency of the entire tilemap, because the component “Tilemap” does have a color-option but I can’t access it via script (“Color/color” is not defined for that component). If there is no direct option, would you guess that it is possible with SpriteRenderer>and just put a sprite infront, instead of a tilemap?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TilemapColorChange : MonoBehaviour
{
    public KeyCode increase;
    public KeyCode decrease;

    private Component caveTilemap;

    private float transparencyLevel = 0.5f;

    void Awake()
    {
    caveTilemap = GetComponent<Tilemap>();
    }

    void FixedUpdate()
    {
        if (Input.GetKeyDown(increase))
        {
            transparencyLevel += 0.5f;
            caveTilemap.SetColor(0,0,0,transparencyLevel);
        }
        if (Input.GetKeyDown(decrease))
        {
            transparencyLevel -= 0.5f;
            caveTilemap.SetColor(0,0,0,transparencyLevel);
        }
    }
}

Thank you a very lot in advance :palms_up_together:

Now, I know what was missing
I simply had to add another “using”-statement … UnityEngine.Tilemaps was missing in my case;

In fact, your way is much more elegant, I implemented it now like follown

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Tilemaps;

public class TMcolor : MonoBehaviour
{
    public Tilemap cave;
    public Color color;

    void Awake()
    {
        
    }

    void Update()
    {
        
    }

    public void ChangeColor()
    {
        color.a = 0.3f;
        cave.color = color;
    }
}

I simply call this function in my OnTrigger event on the players script

thank you a very lot sir, I really appreciate it :+1:

If you mean that you want to change the color that you see on the Tilemap component in Unity, this should work:

public Tilemap tileMap;
public Color color;
public float intensityLevel;

void Update()
{
    color.a = intensityLevel;
    tileMap.color = color;
}

note that color.r, color.g, color.b and color.a works the same as Vector3.x, for example