I am using Unity and coding in C#. I have a game object called Enemy
, which has a script called EnemyMotor
. EnemyMotor
has an int
called ID
. When EnemyMotor
starts, I need to find an ID
value that is not been using by any other instance of EnemyMotor
.
For example: Enemy
one spawns; check if an ID
value of 1 is not being used. Enemy
two spawns; check if an ID
value of 1 is being been use. In this case, it is, so I need to find another ID
value that is not being used. In this case, it should be 2. Continue with Enemy
three, Enemy
four and so on.
How do I go about ensuring a unique ID
value?