Search Unity

Question To interact two buttons simultaneously...(Please Help)

Discussion in 'UGUI & TextMesh Pro' started by GreenBottle, Nov 30, 2020.

  1. GreenBottle

    GreenBottle

    Joined:
    Mar 20, 2019
    Posts:
    1
    Hi,
    I'm developing a way to make two buttons work at the same time and here's the problem.

    There are two types of buttons (A, B) in my project.
    I want to change the image of two buttons at the same time when one trigger enters.
    1. ButtonA's image changes well when the trigger enters the buttonB.
    2. ButtonB has no response when the trigger enters the buttonA. ButtonA only changes.
    I don't know what's wrong with my script. How can I implement the action I want?
    Please help me.

    I can't show you the original script, but I'll show you the structure roughly.

    Code (CSharp):
    1.  
    2. int btnIndex;
    3. Sprite hoverSprite;
    4. Sprite defaultSprite;
    5. Sprite selectedSprite;
    6.  
    7. if(isEnter == true){
    8. buttonA(btnIndex).sprite = hoverSprite;
    9. buttonB(btnIndex).sprite = hoverSprite;
    10.     if(isPressed == true)
    11.     {
    12.     buttonA(btnIndex).sprite = selectedSprite;
    13.     buttonB(btnIndex).sprite = selectedSprite;
    14.     }
    15.  
    16. }
    17. else {
    18. buttonA(btnIndex).sprite = defaultSprite;
    19. buttonB(btnIndex).sprite = defaultSprite;
    20. }