Search Unity

Question How to correctly associate a Action buttons UI to correct character in a party

Discussion in 'UGUI & TextMesh Pro' started by bowerick, Mar 15, 2023.

  1. bowerick

    bowerick

    Joined:
    Jan 6, 2023
    Posts:
    1
    I'm working on a project (am quite new to Unity) that is a small party rpg game (think For the King as reference) where a party of a few (like 3 or so) character take on a small party of enemies in a turn based fight. The characters have a list of 'actions' (basic attack, big attack, defend, heal etc.) that the player needs to be able to select. It should work in a way that when I select a character, all the possible actions that character has have a button on the lower part of the screen. The amount of buttons thus is based on the amount of actions in the list (so not fixed).


    I have been struggling a bit as to how to make this work correctly. Basically there are two 'things' I need to implement. Showing the correct UI element/canvas (with the buttons on it) based on the character I select. And secondly, creating the correct number of buttons on that canvas 'connected' to the corresponding action from the list.

    I have tried different approaches and am curious as to what would be a good way to approach this design wise. Should I for instance create my character prefabs with a canvas element attached that is default disabled (and than parent it to the canvas UI element where I want it to show - bottom of the screen). Or maybe have a single UI element that displays the possible actions on the currently selected character (but also then, what is a nice way to update changes). The problem I keep getting back to is how tightly it is being coupled. The UI element feels like it should be only loosely coupled with the character(actons) but somehow it does need to be coupled (to create the buttons and do the callback when being clicked).


    I am looking for some design advice and would really appreciate some implementation tips as well.

    Somehow this hasn’t been as straightforward as it seemed when starting this :).