Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 NoQxyGen · Aug 09, 2020 at 10:24 PM · user interfaceitemrandomizationitem pickup

Item/Buff Selection UI

Hi. I'm working on a basic 2D platform game like Deadcells. After you beat the boss i want to display a buff selection window which is contains 3 random buffs. Player will choose one of them. These 3 buffs will be chosen randomly among 10 buffs. What is the best way to do this kind of system? Two methods came to my mind.

  1. Buttons on a panel and somehow implement randomization

  2. Use Random.Range with list and select random sprites

Is there any other logical solution? Thanks.

Example Pic. (10/10 paint ability): alt text

test.png (13.5 kB)
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Mrintoxx · Aug 10, 2020 at 08:50 AM

First you must create the "buffs", you can use Scriptable Objects to store the data of each buff.

 using UnityEngine;
 
 [CreateAssetMenu(fileName = "Buff", menuName = "Buffs/Buff", order = 0)]
 public class Buff : ScriptableObject
 {
     public Sprite icon;
     public String description;
 }

And then with right click in project window you can create a Buff. Let's createsomething like 10 buffs.

For the ui : Each tile needs to have a image component and a button. and attach a script with a reference to the button and image :

 using UnityEngine;
 using UnityEngine.UI;
 
 
 public class Slot : MonoBehaviour
 {
     Buff slotBuff;
     Button btn;
     public Image img;

 
     private void Awake()
     {
         btn = GetComponent<Button>();
         img= GetComponent<Image>();
     }

Make also a setup method in same script :

 public void Setup(Buff buff)
     {
         slotBuff = buff
         img.sprite = buff.icon;
         btn.onClick.AddListener(PurchasePlant);
     }
 
  public void PurchasePlant()
     {
         //Stuff to do when the tile is clicked
     }
 

Make a prefab of the tile with the script and the components attached and then delete the tiles in you hierarchy.

In an empty game object attach a script who will instantiate the tiles and contains the list of the buffs.

 public class BuildManager : MonoBehaviour
 {
 public Buff [] listBuff; //in inspedctor set the 10 buffs created earlier
 public GameObject Slot //In inspector set the prefab here
 public Transform slotsContent //In inspector set the parent transform of the tiles
 
 public int numberOfTiles;
 
 private void Start()
     {
         for (int i = 0; i < numberOfTiles; i++)
         {
             GameObject slot = Instantiate(slot, slotsContent.position, Quaternion.identity);
             slot.transform.SetParent(slotsContent);
             slot.GetComponent<ShopSlot>().Setup(listBuff[Random.Range(0, listBuff.Length)].plant);
         }
 
     }
 
 }
 

 

Hope it can help you, may contain some bug code beceause it's untested but should work :)

Comment
Add comment · Show 2 · 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 NoQxyGen · Aug 10, 2020 at 02:29 PM 0
Share

Thank you so much.

avatar image Mrintoxx NoQxyGen · Aug 10, 2020 at 11:34 PM 0
Share

glad to help :)

avatar image
0

Answer by GoldenretriverYT · Aug 10, 2020 at 02:11 AM

What is your problem? I can not find a problem were we can help you?

Comment
Add comment · Show 1 · 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 NoQxyGen · Aug 10, 2020 at 03:17 AM 0
Share

Sorry for the confusion. As I mentioned above I need a buff selection window but i don't know to best way to that. Should i use buttons (1) or sprites (2) or another way? Which solution is the best solution for a item/buff selection UI?

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

233 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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 Pick up Items On Button Press and Add it To Visible Inventory 0 Answers

How to Make an Object Pickup System? 0 Answers

Picking up flashlight? 0 Answers

How to make sure score can't be increased by picking up same item multipe times--new idea 2 Answers

Best Way to do Regular Items and Weapons/Intractable/Special Items. 1 Answer


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