In an example found in W3Schools, I saw that you can give a custom value to an Enum, like this:
enum Months
{
January, // 0
February, // 1
March=6, // 6
April, // 7
May, // 8
June, // 9
July // 10
}
For my game, I often have to check the neighbors of a certain position (UP, DOWN, LEFT, RIGHT), so I made this array:
Vector3Int[] neighborOffsets =
{
new Vector3Int(0, -1, 0), // Bottom
new Vector3Int(-1, 0, 0), // Left
new Vector3Int(0, 1, 0), // Top
new Vector3Int(1, 0, 0) // Right
};
However, if I require a specific and known value, I have to remember which position to access by it's index. So if I explicitly need the TOP direction, I'd have to write: neighborOffsets[2]
.
Is there an easier way to do this with enums? Something like this:
public enum Directions
{
BOTTOM = new Vector3Int(0, -1, 0),
LEFT = new Vector3Int(-1, 0, 0),
TOP = new Vector3Int(0, 1, 0),
RIGHT = new Vector3Int(1, 0, 0)
}
So then if I need the UP direction, I'd just write Directions.TOP?
question from:
https://stackoverflow.com/questions/65901653/how-to-declare-enum-with-vector3-directions