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 Dimitry_Bogov · Aug 24, 2018 at 06:57 PM · textif-statementsintarray list

Help me with text array.

Hi I'm new to programming in unity and I need some help. I'm trying to create an array that holds in text and only one of the texts in the array is enabled (SetActive) once I have clicked the left mouse button the current text that will be disabled and the next text in the array is going to be enabled but I'm having trouble with that this is what I have got so far:

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;

public class Tutorial : MonoBehaviour {

 [SerializeField] GameObject[] tutorialText;
 // Use this for initialization
 void Start () {
     
 }
 
 // Update is called once per frame
 void Update ()
 {
     int tutorialTextLength = tutorialText.Length;
     int textIndex = tutorialTextLength; 
     if(Input.GetMouseButtonDown(0))
            {
         
            }
 }

}

PLEASE HELP

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
1
Best Answer

Answer by eses · Aug 24, 2018 at 07:22 PM

Hi @Dimitry_Bogov


You'll have to learn the basics of loops and iteration.
However, you could do something like this:

 public GameObject[] tutorialText;
 public int index = 0;
 public bool tutorialDone = false;
 
 void Start ()
 {
     foreach (var item in tutorialText) 
         item.SetActive(false);
 }
 
 void Update()
 {
     if (Input.GetMouseButtonDown(0) && !tutorialDone)
         ShowNextText();
 }
 
 void ShowNextText()
 {
     if (index < tutorialText.Length)
     {
         Debug.Log("tick");
 
         tutorialText[index].SetActive(true);
         
         if (index > 0) 
         {
             tutorialText[index-1].SetActive(false);
         }
 
         index++;
     }
     else if (index == tutorialText.Length)
     {
         tutorialText[index-1].SetActive(false);
         tutorialDone = true;
     }
 }



This would show the first object with first click, then the next one. When the last one is shown, click will hide it and the tutorial would be done.

Comment
Add comment · Show 3 · 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 Dimitry_Bogov · Aug 25, 2018 at 06:22 AM 0
Share

Thank you very much this helped a lot. Again I'm new to program$$anonymous$$g and I had no idea what to do but you look like you know what's up so again thanks!

avatar image eses Dimitry_Bogov · Aug 25, 2018 at 08:43 AM 0
Share

@Dimitry_Bogov - good - could you please mark the answer as correct answer if you think it is the correct answer - thanks.

avatar image Dimitry_Bogov eses · Aug 25, 2018 at 01:39 PM 0
Share

No problem

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

154 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 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 get my weapon to stop firing if the ammo <= 0 1 Answer

NullReferenceException: Object Reference not set to an instance of an object 1 Answer

Making text appear when a parameter is met. 1 Answer

Can I create a GameObject Array then fill UI text elements and then somehow use a For Loop to drop an Array of Int values inside those UI text boxes from largest to lowest? 0 Answers

I'm trying to insert input field text into an arraylist 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