Sam_003
Sam_003

Reputation: 13

Change transparency of tile on mouse over : Unity Tilemaps

I am creating a game using unity's tilemap system and cant seem to figure this out. I am trying to create an effect where whichever tile the mouse is above, fades a bit, and when the mouse leaves that tile it goes back to normal. Here is my current code:

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

public class mouseHoverTiles : MonoBehaviour
{
    [Header("Variables")]
    [SerializeField] private Tilemap groundMap;
    [SerializeField] private Camera mainCam;

    private Vector3Int tilePos;
    private Vector3 mousePos;
    private Tile currentTile;

    void Update()
    {
        mousePos = mainCam.ScreenToWorldPoint(Input.mousePosition);
        tilePos = groundMap.WorldToCell(mousePos);

        currentTile = groundMap.GetTile<Tile>(tilePos);

        currentTile.color = new Color(currentTile.color.r, currentTile.color.g,currentTile.color.b, 0.75f);
    } 

}

Not only does this script not work, if it was to work then the tiles would never return back to their original transparency.

Upvotes: 0

Views: 691

Answers (0)

Related Questions