Search Unity

Multi button popup info

Discussion in 'Scripting' started by kz3dart, Dec 17, 2014.

  1. kz3dart

    kz3dart

    Joined:
    Jul 3, 2014
    Posts:
    8


    Task:
    a : for mobile device ( MouseDown, MouseUp etc limit the Update events)
    b : every button (white/blue) toggle color and pop-up menu (same plane different texture ;) )
    c : only one button can be active at a time default position no active buttons
    d : no other buttons for toggle info off and on!!
    e : adjustable for different count of a button

    Task A and B is so simple that it hurts ;) but the rest is killing me ;(.
    I solve A and B many different ways but last it looks like this:
    - every button has C# that toggle bool in one C# script "Button_List" with Update(only one update for this taks) .
    - Button_List(C#) do the rest ; if BtnA=true , set active "info_Container" change texture to InfoA. If BtnA=false hide "info_Container" . I do not have to change back texture because another button load different one so this is OK, but i can press many buttons after a while its mess :(

    Array of bools looks promising but If every button is a toggle i can't make eg: MouseDown set array = false , MouseUp set BtnA true. This is good solution and I have only one Btn On, but I cant set this one to false by toggle because on MouseDown all are false so one is always active.

    My brain melts
     
  2. kz3dart

    kz3dart

    Joined:
    Jul 3, 2014
    Posts:
    8
    To hard or to easy to respond??
     
  3. kz3dart

    kz3dart

    Joined:
    Jul 3, 2014
    Posts:
    8
    ok mayby i help ;)

    Now the code check of I click on buton with value i=0 and only that one is toggle rest of them turn blue and false when i change buton but no toggle ;(.

    I need some function if i== button that is true then toggle if i click other one then turn off them all and only turn on this one.

    Code (CSharp):
    1. void OnMouseDown ()
    2.     {      
    3.         GameObject[] buttons = GameObject.FindGameObjectsWithTag("Info_buttons");  
    4.         for(var i=0; i<buttons.Length; i++){          
    5.      
    6.             if(i!=0){
    7.              
    8.                 buttons[i].GetComponent<InfoBTN>().Press = false;
    9.                 buttons[i].renderer.material.color =  Color.blue;      
    10.              
    11.             }
    12.          
    13.         }              
    14.      
    15.     }
    16. void OnMouseUp ()
    17.   {  
    18.  
    19.    
    20.      if(gameObject.name=="Btn01"){
    21.        Press = !Press;
    22.        if(Press){
    23.          Btn01.renderer.material.color =  Color.red;
    24.        
    25.        }
    26.        if( !Press){
    27.          Btn01.renderer.material.color =  Color.white;
    28.        
    29.        }
    30. }