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
0
Question by JoJoDeath97 · Jul 02, 2019 at 03:58 PM · uitextcanvasgrid

Adding a string to grid layout group

Hey there,

I'm trying to add a small UI element that tracks some quests. I do this by storing a list of quest objects, out of which I want to add a few elements to my UI in the form of a grid. Here is the code I have at the moment.

 public List<Quest> questLog;                // the list containing all the quests

 void Start()
 {
     foreach (Quest q in questLog)
     {
         bool marker = q.questDisplayed;
         string goal = q.questProgress + " / " + q.questGoal;
         string description = q.questLogDescription;
     }
 }

Now my problem is that I can't seem to be able to wrap my head around adding these elements to my grid. I have added a Grid Layout Group with a constraint of 3 columns, and added that to a Scroll View's Content section, according to how this tutorial does it. However, they seem to add an image to the grid and instantiate it, while I want to add 3 different parts to the grid, namely a checkbox and two strings. I could not figure out how to add the text to the grid layout after googling around for some time, so if you have any suggestion as to how I should or can add such components to my grid layout, please leave it in a comment below!

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 akaBase · Jul 02, 2019 at 04:12 PM 0
Share

I advise making a prefab element with a script attached you can pass the Quests info to that you add to the Grid Layout Group. It's the method I have used before when wanting complex dynamic elements added to a Grid Layout Group.

avatar image JoJoDeath97 akaBase · Jul 02, 2019 at 09:27 PM 0
Share

I don't quite understand the advice you're giving here. I understand how to create a prefab with a script added to it, but I don't quite understand what the other part is that you're trying to advice me to do, so could you provide an example of this method? It looks exactly like what I want, with the dynamic element adding to a grid layout group, but I don't quite understand the 'how' of it.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by akaBase · Jul 03, 2019 at 10:44 AM

Reply to comment asking for more Information.


Create an empty GameObject with a couple of Texts and an Image(?) as childen to show the information about the Quest and add a script to it you can pass the Quest to.


Example Prefab Script


     public class QuestInfo : MonoBehaviour
     {
     #pragma warning disable 0649
         [SerializeField] private Text _goalText;
         [SerializeField] private Text _descriptionText;
         [SerializeField] private Image _markerImg;
     #pragma warning restore 0649
     
         public void Setup(Quest quest )
         {
             _markerImg.gameObject.SetActive(quest.questDisplayed);
             _goalText.text = quest.questProgress + " / " + q.questGoal;
             _descriptionText.text = quest.questLogDescription;
         }
     }



And then modify your current script to add the prefab and pass the Quest Object to it.


Example Modified Script


 public class Quests : MonoBehaviour
     {
         public List<Quest> questList;
         public Transform gridLayoutGroupsTransform;
         public GameObject questInfoPrefab;
     
         void Start()
         {
             foreach (Quest quest in questList)
             {
                 GameObject go = Instantiate(questInfoPrefab, gridLayoutGroupsTransform.position, Quaternion.identity);
                 go.transform.SetParent(gridLayoutGroupsTransform); 
                 
                 QuestInfo questInfo = go.GetComponent<QuestInfo>();
                 questInfo.Setup(quest);
             }
         }
     }


Hope that makes more sense now.

Comment
Add comment · 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

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

193 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Canvas is flipping, 2D game 0 Answers

How do I carry over ui text to the next by obtaining the gameobject children 0 Answers

,InputField backspace returns already send text 0 Answers

Unity 5 UI GUI Text Canvas Screen Resolution Adaption Problem 2 Answers

Grid and Canvas react on mouse events simultaneously 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