Search Unity

Accessing multiple components

Discussion in 'Scripting' started by psycocrusher, Nov 26, 2014.

  1. psycocrusher

    psycocrusher

    Joined:
    Jul 24, 2011
    Posts:
    71
    Hi,

    I am converting my game from unityscript to C# and i have a problem the guiTexture's color.
    In unityscript you can change the guiTexture.color.a without affecting the rgb channels.

    I know in c# we have to store the Color in a variable, but i would i go about storing the color of
    multiple guitextures without affecting rgb.

    This is what i got so far but it doesn't really work.
    Code (CSharp):
    1.  
    2.     private Color HalfColor;
    3.    
    4.     void  Start (){
    5.  
    6.         foreach(GameObject GuiOpacity in GameObject.FindGameObjectsWithTag("UnselectedGui")){
    7.  
    8.             HalfColor = GuiOpacity.GetComponent<GUITexture>().color;
    9.         }
    10.   }
    11.  
    12.         FullColor.a = 0.5f;
    13. }
    I tried Color.gray but it also resets rgb values.

    Thank you
     
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    If you have an array of guiTextures (from FindGameObjectsWithTag) and you want to store the color of each, then you likewise need an array of colors
    Iterate with index (instead of foreach) and do colors[index] = objectArray[index].Getcomponent......