Hi in my state machine I have two numbers generated through Random.Range in the void start function, I want to use Mathf.Approximately to check which number has come out higher and to print that in the console, but I am not sure how to do this. Any help would be appreciated.
The code I am using is:
{
int playerDiceRoll;
int enemyDiceRoll;
private BattleStateStart battleStateStartScript = new BattleStateStart ();
public enum BattleStates
{
START,
PLAYERROLL,
ENEMYROLL,
PLAYERCHOICE,
ENEMYCHOICE,
DAMAGECALCULATION,
LOSE,
WIN
}
private BattleStates currentState;
void Start ()
{
currentState = BattleStates.START;
playerDiceRoll = Random.Range (1, 10);
print (playerDiceRoll);
enemyDiceRoll = Random.Range (1, 10);
print (enemyDiceRoll);
if (Mathf.Approximately(1.0f, 10.0f / 10.0f));
print("same");
}
void Update ()
{
Debug.Log(currentState);
switch(currentState)
{
case (BattleStates.START):
//SETUP BATTLE FUNCTION
//create enemy
//choose who goes first based on dice roll
break;
case (BattleStates.PLAYERROLL):
break;
case (BattleStates.ENEMYROLL):
break;
case (BattleStates.PLAYERCHOICE):
break;
case (BattleStates.ENEMYCHOICE):
break;
case (BattleStates.DAMAGECALCULATION):
break;
case (BattleStates.LOSE):
break;
case (BattleStates.WIN):
break;
}
}
void OnGUI ()
{
if(GUILayout.Button("NEXT STATE"))
{
if(currentState == BattleStates.START)
{
currentState = BattleStates.PLAYERROLL;
}
else if (currentState == BattleStates.PLAYERROLL)
{
currentState = BattleStates.ENEMYROLL;
}
else if (currentState == BattleStates.ENEMYROLL)
{
currentState = BattleStates.PLAYERCHOICE;
}
else if (currentState == BattleStates.PLAYERCHOICE)
{
currentState = BattleStates.ENEMYCHOICE;
}
else if (currentState == BattleStates.ENEMYCHOICE)
{
currentState = BattleStates.DAMAGECALCULATION;
}
else if (currentState == BattleStates.DAMAGECALCULATION)
{
currentState = BattleStates.LOSE;
}
else if (currentState == BattleStates.LOSE)
{
currentState = BattleStates.WIN;
}
else if (currentState == BattleStates.WIN)
{
currentState = BattleStates.START;
}
}
}
}