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 /
avatar image
1
Question by Bafelmauk · Jan 13, 2016 at 06:44 PM · c#listprogrammingbuttons

List to buttons

Hello i have code what have list but how i can make so that every item on list have automatic button appeared ? Example i have 5 items then it give me 5 buttons. and when 8 items then 8 buttons.

i make list with this code:

 foreach(Match match in Regex.Matches(page,name)){
             matchList.Add(match.Groups[1].Value);
         }
 
   

  
 
Comment
Add comment · Show 2
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 lassade · Jan 14, 2016 at 08:50 PM 1
Share

This is on editor (in a inspector) or in game (in your game ui)?

avatar image Bafelmauk lassade · Jan 16, 2016 at 01:36 PM 0
Share

inspector i think, im not sure about that. But application point its get html info and then make buttons and when open then there is news

my full code look so:

 using UnityEngine;
 using System.Collections.Generic;
 using System.Component$$anonymous$$odel;
 using System.Linq;
 using System.Net;
 using System.Text;
 using System.Text.RegularExpressions;
 using System.Threading;
 using System.Collections;
 using UnityEngine.UI;
 
 
 public class WebGrabber : $$anonymous$$onoBehaviour {
     public Text proov;
     List<string> matchList = new List<string>();
     // Use this for initialization
     void Start () {
         WebClient w = new WebClient ();
         string page = w.DownloadString ("http://blog.counter-strike.net/index.php/category/updates/");
         string name = "Release (.*?)</a>";
         foreach($$anonymous$$atch match in Regex.$$anonymous$$atches(page,name)){
             matchList.Add(match.Groups[1].Value);
         }
         for (int i = 0; i < matchList.Count; i++) 
         {
             proov.text += ("Release" + matchList[i] + "\n");
         }
     }
     void Update () {
     }
 }

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by antx · Jan 15, 2016 at 02:50 PM

Make a Button and make a prefab from it. Then in your script you can instantiate the button.

Best is if you make a class for your buttons and attach it to your prefab button so you can easily work with them.

 public class BafelmaukButton : MonoBehaviour {
     public Text label; // asign the buttons text GO here in the inspector.
 }
 
 public class ButtonListScript : MonoBehaviour {
     public Canvas canvas; // asign your canvas here in the inspector.
     public BafelmaukButton myButtonPrefab;
 
     void Start () {
         // make sure your matchlist is also somewhere in code
         for(int i = 0; i < matchList.Count; i++) {
             BafelmauButton myBB = Instantiate(myButtonPrefab);
             myBB.transform.SetParent(canvas);
             myBB.Label = "Button " + i;
             myBB.transform.positon = new Vector3 (100, i * 80, 0);
         }
     }
 }
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 lassade · Jan 15, 2016 at 06:01 PM 1
Share

Interesting i never tried instantiating a prefab this way

avatar image Bafelmauk · Jan 16, 2016 at 02:06 PM 0
Share

I dont know why but there was problem with this code i tried differently but best was that there was some errors:

    for(int i = 0; i < matchList.Count; i++) {
              BafelmauButton myBB = Instantiate(myButtonPrefab);
              myBB.transform.SetParent(canvas);
              myBB.Label = "Button " + i;
              myBB.transform.positon = new Vector3 (100, i * 80, 0);
          }

avatar image palalopea Bafelmauk · May 14, 2018 at 07:22 PM 0
Share

hello, did you fixed it?

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

58 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

Related Questions

Multiple Cars not working 1 Answer

Button Action Triggering Multiple Times Per Click? 1 Answer

Filling array with Scribtable Objects automaticly? 1 Answer

A node in a childnode? 1 Answer

Distribute terrain in zones 3 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