- Home /
Need to code Enemy Attacking Portion of a Pokemon/Turned Based Combat System
Once the player has clicked a button to attack and the damage and such to the enemy has been calculated, I then need to run the function to calculate the damage the player takes AND DISPLAY THE TEXT/INFO the player needs to know on screen long enough/and possibly give the option to skip the text. video
Answer by Masterben135 · May 28, 2015 at 03:45 PM
You could create a textBox gameObject once everything has been calculated, passing in a List of strings (i.e. the damage and such that has already been calculated) that the textBox object will need to display. Then in the textBox's update function, you keep a timer (using Time.deltaTime) that changes the displayed string to the next string in the List.
Also in the same update, you could check for any user input that would immediately skip to the next string. Once every string has been looped through, the gameObject is destroyed.
so for example I would write my code like this (where eaTextGO is the game object for the text, and I would insert the timer at the // marks, but what would I type?
public void EnemyAttacking ()
{
eaTextGO.SetActive (true);
eaText.text = "Enemy Is Attacking... ";
//insert timer here???
//This is where the damage is calculated/move is picked
enemyG.RollDice ();
AttackName ();
eaText.text = "Enemy Used " + enemy$$anonymous$$oveName + " ...";
//insert timer here???
//actual damage is substracted
if (enemy$$anonymous$$oveName == "$$anonymous$$ick Attack")
{
kickAttack ();
Debug.Log ("test");
}
//insert timer here???
eaTextGO.SetActive (false);
//this is were we switch back to allowing the player to attack
state$$anonymous$$achine.Attack$$anonymous$$enu ();
}
You're going to have to restructure that code, if you're not going to use a coroutine. You can't just insert "wait" timers in normal scripts or functions.