Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

System Behind Following Clicked Buttons

Discussion in 'Scripting' started by kapopixel, Jul 16, 2019.

  1. kapopixel

    kapopixel

    Joined:
    Apr 2, 2017
    Posts:
    54
    Hello folks,

    Basically, I am trying to implement this system:
    steps12345.png
    To explain:
    1) We click any button so it is activated and turns green.
    2) Then click any other button so the first clicked button passes "1" to the second click button.

    Of course there will be limits like some of the buttons will reach maximum value and even we try to pass "1" to them system will not accept it. But above is the main logic.

    Do you have any suggestions on how I can achieve this?
     
  2. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,556
    You seem to be letting out a lot in your description. For one, 'passing "1"' doesn't seem to be all, you also seem to change the Name of the buttons by some rule, which you imply with 'reach Maximum value'.

    But if all you want to do is increasing and decreasing the value of the button clicked and last button clicked, there is no need for complex logic: simply remember the last button clicked, and when it's not null, reduce last button's Name, increase current buitton's Name and you are done.

    pseudo-code:

    Code (CSharp):
    1. if (lastButton != null) {
    2.     currentButton.buttonValue += 1;
    3.     lastButton.buttonValue -=1;
    4.     currentButton = lastButton;
    5. }
     
    kapopixel likes this.
  3. kapopixel

    kapopixel

    Joined:
    Apr 2, 2017
    Posts:
    54
    Hey @csofranz thanks for your reply. In this case I need to reach currentButton and lastButton information. Do you have suggestions how can I achieve this?