Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Ochreous · Aug 26, 2013 at 09:42 PM · c#listelements

C# Displaying List Elements in Multiples

Hi everyone, I'm trying to display list elements in multiples. I want it to display it in multiples of five and I want it to display like the following below but with just one line of Debug.Log. I've tried using for loops and messing with their proportions. But that didn't work and I'm not sure what I'm doing wrong.

 Debug.Log(someList[5]);
 Debug.Log(someList[10]);
 Debug.Log(someList[15]);
 Debug.Log(someList[20]);
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 markedagain · Aug 26, 2013 at 09:46 PM

     for (int i = 5; i <= 20; i = i + 5) {
         Debug.Log(someList[i]);
     }
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 Ochreous · Aug 26, 2013 at 10:06 PM 0
Share

How do you get that to work with a GUI.Button? I would like for it to go through the multiples as I click the button. I tried the following below but it goes through the entire list when I click on the GUI.Button once.

 if (GUI.Button(new Rect(10, 10, 50, 50), "SomeButton")){
      for (int i = 5; i <= 20; i = i + 5) {
     Debug.Log(someList[i]);
     }
 }
avatar image markedagain · Aug 27, 2013 at 03:06 AM 0
Share

you should setup a global variable and in your button click simply keep adding currentNum = currentNum + 5

avatar image ArkaneX · Aug 27, 2013 at 09:44 AM 0
Share

Like this:

 private int _count = 0;
 
 if (GUI.Button(new Rect(10, 10, 50, 50), "SomeButton")){
     Debug.Log(someList[_count]);
     _count += 5;
 }

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

17 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

Related Questions

A node in a childnode? 1 Answer

C# Randomly Adding Elements from stringListA to stringListB 1 Answer

C# Adding Multiple Elements to a List on One Line 5 Answers

C# Dividing Gameobject List by Half 1 Answer

C# Displaying a List in Series 2 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