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 /
  • Help Room /
avatar image
0
Question by Pejovski · Dec 22, 2015 at 02:15 PM · inputtextinputfield

Input Field Problem

I have been all day trying to change my code and add Input Field instead answers, but with no progress, this is my code:

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 using System.Collections.Generic;
 
 public class QuestionDialogMulti : QuestionDialogBase {
 
     // Prefab za toa kako izgleda eden odgovor
     public GameObject answer;
 
     // Momentalno prasnje so povekje odgovori
     private MultiQuestionXMLBase.Question currentQuestion;
     private MultiQuestionXMLBase questionBase;
     // Transform komponentata na dialogot
     private RectTransform rect;
     // Lista na objekti odgovori
     private List<GameObject> answers;
     // Visina
     private float height;
 
     void Start () {
 
         questionBase = GameObject.FindWithTag("QuestionBase").GetComponent<MultiQuestionXMLBase> ();
         // Zemame transform
         rect = GetComponent<RectTransform> ();
         // Zemame visina
         height = rect.sizeDelta.y;
         // Kreirame prazna lista od odgovori
         answers = new List<GameObject>();
 
     }
 
     // Pri prikaz generiraj novo prasanje
     public override void SetVisible(bool visible) {
         base.SetVisible(visible);
         if (visible) {
             SetQuestion();
         }
     }
 
 
     public void SetQuestion() {
 
         // Gi briseme site predhodni odgovori
         foreach (GameObject go in answers) {
             Destroy(go);
         }
         answers.Clear();
 
         // Generirame novo prasanje
         currentQuestion = questionBase.Questions[Random.Range (0, questionBase.Questions.Count)];
         // Go postavuvame tekstot na prasanjeto
         question.text = currentQuestion.question;
         // Za sekoj odgovor
         for (int i = 0; i < currentQuestion.answers.Count; i++) {
             // Kreirame nov objekt odgovor (od prefabot za izgled na odgovor)
             GameObject tmpAnswer = (GameObject) Instantiate(answer);
             // Go dodavame vo listata na odgovori
             answers.Add(tmpAnswer);
             // Go vgnezduvame  vo dialogot
             tmpAnswer.transform.SetParent(transform, false);
             // Mestime tekst na odgovorot
             Text tmpText = tmpAnswer.GetComponentInChildren<Text>();
             tmpText.text = currentQuestion.answers[i].answer;
             // Mestime koja funkcija da se povika pri klik na odgovorot
             tmpAnswer.GetComponent<Button> ().onClick.AddListener(
                 () => ButtonClicked(tmpText));
             // Mestime pozicija vo dijalogot
             RectTransform tmpRect = tmpAnswer.GetComponent<RectTransform> ();
             //Ne treba ova
             //tmpRect.anchoredPosition = new Vector2(tmpRect.anchoredPosition.x, tmpRect.anchoredPosition.y - (tmpRect.rect.height * i));
         }
         // Go zgolemuvame dijalogot za da gi sobere site odgovori
         rect.sizeDelta = new Vector2(rect.sizeDelta.x, height + (answer.GetComponent<RectTransform>().rect.height * (currentQuestion.answers.Count - 1)));
 
         
     }
 
     // Funkcija koja se povikuva pri klik na odgovor.
     public void ButtonClicked(Text value) {
 
         // Ako e tocen odgovorot povikaj event Answered ako ne generiraj novo prasanje
         string text = value.text;
         for (int i = 0; i < currentQuestion.answers.Count; i++) {
             if (text == currentQuestion.answers[i].answer) {
                 if (currentQuestion.answers[i].correct) {
                     Answered();
                 } else {
                     SetQuestion();
                 }
                 break;
             }
         }
 
     }
 
 }
 

The script is in this object http://i.imgur.com/T1PZEqV.jpg, and i have prefab Answer which has Button script and child with text script. So my code now is generating as clones answers as i have in my QuestionBase. And door opens if the correct answer is clicked.

But i cant figure out how to make different type of answer with Input Field so when the right answer is typed the door to get oppened. Tnx for ur time :D

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

0 Replies

· Add your reply
  • Sort: 

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

35 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

Related Questions

How do I let users change the background color of a selected word in an input field? 0 Answers

Unity 5.3 Caret is missing on mobile devices 0 Answers

How to temporarily disable arrow keys controlling first-person controller in order to write text in 3D text input box 2 Answers

I cant Multiply integer from Input Field 1 Answer

Input field android problems 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