- Home /
The question is answered
How do i make a BattleLog?
I'm trying to make a battle log like this:
This is the code i use for it now:
if (Turn == 3) {
BattleResults.text = PS.PlayerName + " vs " + Mname + "\n///////////////////////////////\n\n" + PS.PlayerName + " won the battle.\n" + PS.PlayerName + " has " + PS.CurrHealth + " HP left.\n\n ' Gains '\n\nYou found: " + Mcoins + " Coins!\nYou gained " + Mxp + " Exp.";
Debug.Log ("Turn = 3");
PC.Coins += Mcoins;
PS.Exp += Mxp;
Turn = 1;
} else if (Turn == 4) {
BattleResults.text = PS.PlayerName + " vs " + Mname + "\n///////////////////////////////\n\n" + Mname + " won the battle.\n" + Mname + " has " + Mhp + " HP left.\n\nYou got 0 Health left, heal yourself int the 'Healing well'\n";
Debug.Log ("Turn = 4");
PS.CurrHealth = 0;
Turn = 1;
}
and this is how it looks.
I want this text to be there too, so i'm thinking that i'm gonna need something like a Log... like this...
if (Mhp >0 && PlayerHealth >0 && turn == 1){Debug.Log("NAME" hit "ENEMY" for x "DAMAGE", "ENEMY" has x "ENEMYHP" left.); } But like.. Add it to the text file instead of to the Console log.
So my question is how am i going to do this?
What's the question? Are you asking how to create an external text file with the log data?
$$anonymous$$y question is.. How can i do it like this: using UnityEngine; using System.Collections;
public class BATTLE : $$anonymous$$onoBehaviour {
public string playername = "PlayerName";
public string enemyname = "EnemyName";
public int Playerhp = 100;
public int playerdmg = 10;
public int Enemyhp = 75;
public int enemydmg = 5;
public int turn;
public int whowon = 0;
public bool Inbattle;
public int goldfromenemy = 10;
public int xpfromenemy = 10;
public void battle(){
Inbattle = true;
turn = 1;
Debug.Log (playername + " vs " + enemyname + "\n\n");
while(Inbattle == true){
if (turn == 1 && Enemyhp >0 && Playerhp >0){
Enemyhp -= playerdmg;
Debug.Log (playername + " hit " + enemyname + " for " + playerdmg + ", " + enemyname + " has " + Enemyhp + " left." );
turn = 2;
}
else if(turn == 2 && Enemyhp >0 && Playerhp >0){
Playerhp -= enemydmg;
Debug.Log (enemyname + " hit " + playername + " for " + enemydmg + ", " + playername + " has " + Playerhp + " left." );
turn = 1;
}
else if(Playerhp <= 0 && Enemyhp <= 0){
if(Playerhp >0){
whowon = 1;
break;
}else if(Enemyhp >0){
whowon = 2;
break;
}
}
}
if(whowon == 1){
Debug.Log ("\n\n <-- Battle results -->\n" + playername + " won the battle and has " + Playerhp + " left.\n\n");
Debug.Log("You earned:\n" + goldfromenemy + " gold.\n" + xpfromenemy + " Exp." );
}else if(whowon == 2){
Debug.Log ("\n\n <-- Battle results -->\n" + enemyname + " won the battle and has " + Enemyhp + " left.\n\n");
Debug.Log("You can heal yourself at the healing fountain." );
}
}
}
but ins$$anonymous$$d of Debug.Log(); i get it desplayed on the screen like if it was a text component. is there any way to do this?
So you want to convert all those Debug.Logs to be text on screen?
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class LogTest : $$anonymous$$onoBehaviour {
public Text _Text;
public void AddTextToLog(string value)
{
_Text.text += value + System.Environment.NewLine;
}
}
it worked! I did nott know that you could do _Text.text += to add more text to _Text i've tried _Text.text.add and everything else i could think of, but i could not find a way to add more text. But it worked so im happy now.
Thank you for helping me even though you did not understand my question completely. i'm not good at explaining :)
Follow this Question
Related Questions
How to display UI Text on GameObject in script? 0 Answers
Multiple NPCs 1 Answer
Multiple Cars not working 1 Answer
Adjusting UI to cellphone screen size 0 Answers