Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Jul 13, 2016 at 10:41 PM by Le-Pampelmuse for the following reason:

The question is answered

avatar image
0
Question by XenitoX · Jul 13, 2016 at 07:03 PM · c#2duitext

How do i make a BattleLog?

I'm trying to make a battle log like this:

alt text

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. alt text

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?

mybattlelog.png (16.7 kB)
currbattle.png (8.9 kB)
Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jessespike · Jul 13, 2016 at 07:07 PM 0
Share

What's the question? Are you asking how to create an external text file with the log data?

avatar image XenitoX Jessespike · Jul 13, 2016 at 07:49 PM 0
Share

$$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?

avatar image Jessespike · Jul 13, 2016 at 08:08 PM 1
Share

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;
     }
 }

avatar image XenitoX Jessespike · Jul 13, 2016 at 09:39 PM 0
Share

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 :)

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

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

How do I change scene with two ui canvas text 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges