Right, so I’m trying to make a rough turn-based RPG inside unity. My code currently looks like this;
///<summary>The folowing code outlines the functions and routines that make up the battle system,
///to begin with the program fetches the stats of the enemy and the player (HP, MP, Strength
///and resislience) and makes them the value of their respective varibles.
///The main loop can then begin, the progam will first check the HP values of both parties
///player first, to determine wether their has been a win or a loss.
/// A "coin" is then tossed to decide turn order, if the coin "lands" on "heads"
/// the player can take their action first on that turn. </summary>
//Libaries are called here.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class Battle_System : MonoBehaviour
{
//Defintion of public varibles
public Text BattleLog; //The battle log, tells the player what's happening.
public Text HPCount; //The HP count, shows the remaining HP of the player.
public Button Slash; //The button for the slash action, dose a physical attack
//Player Stats
public int P_HP;
public int P_MP;
public int P_Strength;
public int P_Resilience;
//Enemy Stats
public int E_HP;
public int E_MP;
public int E_Strength;
public int E_Resilience;
//Definiton of private varibles
private int coin; //The coin that'll be tossed before each round
private int damage; //How much damage a target takes from an attack, used in calculations
//Defintion of functions
//Hides or shows the player's action buttons
//Initiates the varibles
void Start()
{
//Explains to the player that they've encountered an enemy.
BattleLog.text = ("Enemy approaches...");
//Gives the player's stats a value
P_HP = 20;
P_MP = 10;
P_Strength = 5;
P_Resilience = 2;
//Gives the Enemy's stats a value
E_HP = 12;
E_MP = 10;
E_Strength = 5;
E_Resilience = 2;
// Tells the player their current HP
HPCount.text = ("HP: " + P_HP);
//Sets the existance of the Action buttons (Slash, Cast, Examine, and Satchel)
//to false to stop the player spamming it and messing up the game
}
//The Main Loop
void Update()
{
// The program waits 5 seconds to allow the player to read the battle log
//The HP of both parties are checked to dermine whether the battle has been won or lost
if (P_HP <= 0)
{
//Player has no HP, player loses
BattleLog.text = "You Lose...";
}
else if (E_HP <= 0)
{
BattleLog.text = "You Win!";
}
//Only goes through the following if both sides have HP remaining
else
{
//The coin is flipped to detrmine the turn order for this round.
coin = Random.Range(0, 2);
Debug.Log("Coin=" + coin);
if (coin == 0)
{
//Heads, player gose first
BattleLog.text = "Your turn";
}
else if (coin == 1)
{
//Tails, enemy dose first
BattleLog.text = "Enemy's turn";
}
}
}
}
As you can see I have a battle log (which is just a UI text box), the text of which changes as the battle progresses, the problem is that the text is changing far too fast for the player to read. In the documentation I learned that there’s a method called “wait for seconds”, but it doesn’t seem to get along with void update(), any fixes?