Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by Vexified · Oct 24, 2015 at 11:12 PM · c#xmlbutton trigger eventslabel

Getting Questions and Answers from XML file and applying them to the UI

I made the layout of the game, but the coding is throwing me off. How do I make it so instead of making a new label for every question, make it so that the text of the Label changes? When the question changes the answer changes as well so that it isn't True-True-True-True for the entire game.

Would it be possible if the questions were made in a XML file?

Comment
Add comment · Show 3
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 RyanAchtenSoma · Oct 24, 2015 at 11:37 PM 0
Share

You should really provide more detail in you question; what is your current code/Unity setup and what are you using for this 'label' - is this a Unity UI element or are you referring to an X$$anonymous$$L element?

Using X$$anonymous$$L to host the questions should be easily achievable. You should have a look at the existing resources within the Unity community on the use of X$$anonymous$$L within Unity; by the sounds of what you want, this should be really simple. I would recommend using the X$$anonymous$$L Document class, check out the $$anonymous$$SDN docs on its usage and existing posts on Unity Answers such as this, to get an idea on how this would be achieved.

avatar image Vexified RyanAchtenSoma · Oct 24, 2015 at 11:43 PM 0
Share

I'm not that advanced with C# and Unity. I'm a web developer.

avatar image Vexified RyanAchtenSoma · Oct 24, 2015 at 11:59 PM 0
Share

Also, it is a Unity UI element.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Statement · Oct 24, 2015 at 11:29 PM

It doesn't matter what source the data is coming from. Load it into Data objects you store in memory. Etc define a class for one question and then keep a list or dictionary of them.

 public class Question
 {    
     public string text;
     public string[] answers = new string[4];
     public int answerId;
 }

Keep a list of your questions and the current question

 List<Question> questions = new List<Question>();
 Question currentQuestion;

And create them somewhere as part of your loading

 while (CanCreateQuestionFromXml())
     questions.Add(CreateNextQuestionFromXml());

And pick one at random etc..

 currentQuestion = questions[Random.Range(0, questions.Count)];

And update your UI...

 ui_question.text = currentQuestion.text;
 ui_answer1.text = currentQuestion.answers[0];
 ui_answer2.text = currentQuestion.answers[1];
 ui_answer3.text = currentQuestion.answers[2];
 ui_answer4.text = currentQuestion.answers[3];

And respond to button press etc...

 public void OnAnswer1()
 {
     correct = currentQuestion.answerId == 0;
     RefreshUI();
 }
 public void OnAnswer2()
 {
     correct = currentQuestion.answerId == 1;
     RefreshUI();
 }
 public void OnAnswer3()
 {
     correct = currentQuestion.answerId == 2;
     RefreshUI();
 }

And so on...

Comment
Add comment · Show 2 · 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 Vexified · Oct 24, 2015 at 11:45 PM 0
Share

Alright, so if I am using X$$anonymous$$L for the my data, what would be the structure of the X$$anonymous$$L file?

avatar image RyanAchtenSoma Vexified · Oct 25, 2015 at 12:53 AM 0
Share

The above approach uses the Generic Dictionary, check out the linked tutorial to get an idea of how this works.

So to use this you need to parse the X$$anonymous$$L document and store the nodes holding the question strings as the dictionary $$anonymous$$ey (using something like XmlNode.SelectNodes("Questions").InnerText) and then store the nodes holding the answers as the dictionary Value (as detailed in the code provided above).

If you haven't used X$$anonymous$$L before, you might want to get an idea of the basic syntax it uses (check out this W3Schools doc)

avatar image
0

Answer by adityakin9 · Apr 07, 2018 at 07:46 AM

https://welookups.com/xml/xml_syntax.html

welookups XML Tutorial XML Syntax Rules « Previous Next Chapter »

The syntax rules of XML are very simple and logical. The rules are easy to learn, and easy to use. XML Documents Must Have a Root Element

XML documents must contain one root element that is the parent of all other elements:

 <subchild>.....</subchild>
  

,use this site https://welookups.com/ HTML Tutorials « HTML Home Next Chapter HTML »

HTML

HTML is very important of web page you can create your web pages.

This tutorials teaches you everything about HTML and HTML5.

It's is very simple

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

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

33 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

Related Questions

WHAT TO DO? ArgumentOutOfRangeException: Index is less than 0 or more than or equal to the list count. 1 Answer

I can't save xml file in iOS project during the runtime! (written by unity/C#) 0 Answers

Change scene by tapping a button in unity 5 UI System 1 Answer

How to work with XML for dialogues systems (Handling expression, name, etc)? 0 Answers

Windows Application : using Unity vs using native C# plus WPF 1 Answer


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