Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Resolved Create buttons with player data (using C#)

Discussion in 'Getting Started' started by Kaesesnack, May 16, 2024.

  1. Kaesesnack


    Apr 10, 2024
    Moin :)

    I want buttons to reflect specific player data.
    In this case it is an invisible CardID (BigInt), and two text fields that display the name and card level.

    Using the CardID, I would like to read the database so that all cards that have this CardID as ParentID are displayed below
    have saved, i.e. all subordinate maps.

    This is much easier than assigning each card a single place in the structure, which is intended to be built like a family tree.

    Unfortunately, I don't know exactly how to do this in the best way.
    Can I actually assign the three variables I mentioned to a new button?

    Kind Regards
  2. spiney199


    Feb 11, 2021
    You would assign them to a custom component that lives on the same game object as your button (likely a prefab that you instantiate as you need).

    As in, instantiate prefab via the component, assign data to said component, and it modifies the button as necessary.
    Kaesesnack likes this.
  3. Kaesesnack


    Apr 10, 2024
    Hey Spiney :)

    So something like this?
    - Canvas with attached C# Script for data
    - Button
    - Textfield 1
    - Textfield 2

    I'm currently working on reading the data from the database
    and save them:

    Then I have to assign them from there when instantiating.
    Before I instantiate the buttons, I will take a closer look at the UI toolkit, which was recommended to me here in the forum.

    Thanks for your answer :)