Question by
UnovaRydrake · May 20, 2019 at 12:19 AM ·
c#enumturn-based
My public enum isn't functioning like I want it to
So in the code below, the state START will wait the 3 seconds until transitioning into PTURN, after that I have a button in Unity that corresponds to the Attack function at the bottom, when this button is pressed t transitions to PATTACK but only for a frame and then reverts back to PTURN, even after the 2 seconds have passed it transitions to ETURN but PTURN is still active. My main question is what makes the transition from START to PTURN any different from the transition from PTURN to PATTACK and then ETURN?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TBCController : MonoBehaviour {
public enum BattleStates
{
START,
PTURN,
PATTACK,
PSKILL,
ETURN,
DIE,
WIN
}
private BattleStates CurrentState;
public GameObject CombatUI;
void Start ()
{
CombatUI.SetActive(false); //Starts with a cutscene or somethin
CurrentState = BattleStates.START; //START has a delay for said cutscene
}
void Update ()
{
Debug.Log(CurrentState);
switch (CurrentState)
{
//Battle sequence
case (BattleStates.START):
StartCoroutine("TransitionFromStart");
break;
case (BattleStates.PTURN):
CombatUI.SetActive(true); //makes the UI show up
break;
case (BattleStates.PATTACK):
StartCoroutine("TransitionToE");
break;
case (BattleStates.PSKILL):
StartCoroutine("TransitionToE");
break;
case (BattleStates.ETURN):
break;
case (BattleStates.DIE):
break;
case (BattleStates.WIN):
break;
}
}
IEnumerator TransitionFromStart()
{
while (true)
{
yield return new WaitForSeconds(3f);
CurrentState = BattleStates.PTURN;
}
}
IEnumerator TransitionToE()
{
while (true)
{
yield return new WaitForSeconds(2f);
CurrentState = BattleStates.ETURN;
}
}
public void Attack()
{
if(CurrentState == BattleStates.PTURN)
{
CurrentState = BattleStates.PATTACK;
}
}
public void Skill()
{
if (CurrentState == BattleStates.PTURN)
{
CurrentState = BattleStates.PSKILL;
}
}
}
Comment