Hello everyone,
i need some help. I make a 2d topdown tilebased game. Every Tile is 32x32 (Like you can see in Picture).
no o got diferent layers like: Ground, Walls, Roof.
Now i need to dedect when a player is under a Roof tile to make this layer Invisible (when player is in a building)
right now i got on every Rooftile object a collider and a script attached to make Roof invisible like following script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RoofVisibility : MonoBehaviour
{
void Update()
{
if (ConstantFile.RoofVisibility == false)
{
GetComponent<SpriteRenderer>().enabled = false;
}
else
{
GetComponent<SpriteRenderer>().enabled = true;
}
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "Player")
{
ConstantFile.RoofVisibility = false;
}
}
void OnTriggerExit2D(Collider2D other)
{
if (other.gameObject.tag == "Player")
{
ConstantFile.RoofVisibility = true;
}
}
}
the problem is, everyitme when the player moves from tile to another tile it will enable and disable the Roof.
has anyone a better solution for this?
