In my Grid RPG, the minimap draws a wall when the player is in front of one.
To not let it instantiate inifinite number of walls, it checks first if there’s already a wall on the position with the same rotation. This works perfect except when the rotation of the wall is 180, it still creates an infinite number of walls then. I can’t figure out why and I don’t know any other way to fix it.
I have to use EulerAngles and not RectTransform.rotation because I need to modify the rotation of the walls.
here’s a small piece of code that creates a wall after it checks if it isn’t created yet.
public void CreateWall(Vector3 pos)
{
Vector2 wallPos = new Vector2(Mathf.Round(pos.x * 10 - 10), Mathf.Round(pos.z * 10 + 10));
if(!CheckForWall(wallPos))
{
GameObject spawnedWall = (GameObject)Instantiate(wall);
spawnedWall.transform.SetParent(wallsPanel.transform);
spawnedWall.GetComponent<RectTransform>().anchoredPosition = wallPos;
spawnedWall.GetComponent<RectTransform>().eulerAngles = playerSprite.GetComponent<RectTransform>().eulerAngles;
spawnedWall.GetComponent<RectTransform>().localScale = new Vector3(1, 1, 1);
walls.Add(spawnedWall);
}
}
public bool CheckForWall (Vector2 pos)
{
for (int i = 0; i < walls.Count; i++)
{
if (walls_.GetComponent<RectTransform>().anchoredPosition == pos && walls*.GetComponent<RectTransform>().localEulerAngles.z == playerSprite.GetComponent<RectTransform>().localEulerAngles.z)*_
{
return true;
}
}
return false;
}