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 /
avatar image
0
Question by Malhalar · Jan 20, 2020 at 12:32 AM · textguitextlists

How to create a review of previous updates

Hi everyone. Very simply put, I have a button which ends the player's turn and ages the character. I want the textbox to print of the player's age at the end of each turn using the following code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using TMPro;
 
 public class Eventmanager : MonoBehaviour
 {
     TextMeshProUGUI count;
     
 
     // Start is called before the first frame update
     void Start()
     {
         count = GetComponent<TextMeshProUGUI>();
     }
 
     // Update is called once per frame
     void Update()
     {
         count.text = "Age: " + Character.Age + "\n";
     }
 }


Obviously, the above code just creates an area called "Age:" and updates the character's age on update. I want the script to create a new line and show the new age every time the age button is clicked. I'm assuming I will have to create a list that stores all previous ages however I'm yet to understand how I can do that. I have experimented with using a list but I keep getting "cannot implicitly convert" errors and several other problems.

TIA

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by IINovaII · Jan 20, 2020 at 03:15 AM

Your assumption is quite correct. A list will do the trick. The "cannot implicitly convert" error was probably due to converting an int to string. Since I don't know how age is implemented, the answer might not that accurate but hopefully give you an idea on how to solve your problem.

 public class Eventmanager : MonoBehaviour
 {
     [SerializeField]
     private Button _btnAge; // The button to increase age
 
     [SerializeField]
     private TextMeshProUGUI _txtAge;
 
     private List<int> _storedAges = new List<int>(); //List with all the ages
 
     private int _previousAge = 0; //The starting value of this field is whichever age your character starts with.
 
     private void Awake()
     {
         _btnAge.onClick.AddListener(new UnityAction(() => BtnAge_OnClick())); // This will add the function BtnAge_OnClick as a listener which means whenever the button is clicked, this function will be executed
     }
 
     private void BtnAge_OnClick()
     {
         _previousAge++;
         _storedAges.Add(_previousAge);
 
         string ageString = "";
 
         for (int i = 0; i < _storedAges.Count; i++)
         {
             ageString += "Age: " + _storedAges[i] + "\n";
         }
         _txtAge.text = ageString;
     }
 }
Comment
Add comment · Show 1 · Share
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 Malhalar · Jan 20, 2020 at 11:23 AM 0
Share

Thanks for your response. $$anonymous$$y aging mechanic is just a very simple script attached to the "Age" button as seen below.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class AgeScript : $$anonymous$$onoBehaviour
 
 {
     public static int PlayerAge;
 
     public void AgePlayer()
 
     {
         PlayerAge++;
     }
 }

The current player age is then stored in the character script under Age as referenced in the code from OP. I had a feeling that this is a very roundabout way of doing this and I now think that is even more true. Should I transfer everything from the AgePlayer script into the script for the event manager? Not entirely certain how but should be able to figure it out.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

124 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Fade in text one character at a time 3 Answers

Accessing a certain prefab and it's children 1 Answer

How can I use special characters (symbols) in GUI.Label " " and so on? 1 Answer

How to display text using javascript ? 1 Answer

GUIText in 2D project is not rendering anywhere 0 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