MIF_E31221357/Assets/Scripts/MazeNode.cs

60 lines
1.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MazeNode : MonoBehaviour
{
public enum Directions
{
TOP,
RIGHT,
BOTTOM,
LEFT,
NONE,
}
[SerializeField] GameObject topWall;
[SerializeField] GameObject rightWall;
[SerializeField] GameObject bottomWall;
[SerializeField] GameObject leftWall;
Dictionary<Directions, GameObject> walls = new Dictionary<Directions, GameObject>();
public Vector2Int Index { get; set; }
public bool visited { get; set; } = false;
Dictionary<Directions, bool> dirflags = new Dictionary<Directions, bool>();
public bool isWalkable = true;
void Awake()
{
walls[Directions.TOP] = topWall;
walls[Directions.RIGHT] = rightWall;
walls[Directions.BOTTOM] = bottomWall;
walls[Directions.LEFT] = leftWall;
}
private void SetActive(Directions dir, bool flag)
{
walls[dir].SetActive(flag);
}
public void SetDirFlag(Directions dir, bool flag)
{
dirflags[dir] = flag;
SetActive(dir, flag);
}
public bool IsWall(Directions dir)
{
if (dirflags.ContainsKey(dir))
{
return dirflags[dir]; // true jika ada dinding
}
return true; // default: ada dinding kalau belum diset
}
}