• 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 programming 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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 to set the position of these Texts ?? 0 Answers

How can i make an if statement fire only when the player doesn't hit a button? 1 Answer

NullReferenceException: Object Reference not set to an instance of an object 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

If an integer ends with an 1. 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges