Search Unity

Changing a texture programmatically.

Discussion in 'Scripting' started by g0tNoodles, Jul 25, 2011.

  1. g0tNoodles

    g0tNoodles

    Joined:
    Nov 28, 2010
    Posts:
    193
    Loes, I currently have a GUITexture with a blue texture on it. When I click on this I would like it to swap to another texture (which is also blue but will make it look like its highlighted). Is this possible to do programmatically or do I have to do it through another method? I can only use 2D based object for this, if I use 3D it doesn't perform as required.

    How would one go about doing this?

    Thanks,

    Cas
     
  2. oneXwork

    oneXwork

    Joined:
    Mar 3, 2011
    Posts:
    266
    guiTexture.color = Color(0,0,1,0.5);
    An example only
    Set it to the color you want.....
     
  3. g0tNoodles

    g0tNoodles

    Joined:
    Nov 28, 2010
    Posts:
    193
    Hi, thanks for the reply. I can't just change the colours as what it needs to change to is a whole new image. Both images have a of detail in them so just changing the colour won't be right.

    Any idea as to how to change the original texture/image to the new one i need to put in?

    Cheers
     
  4. bdev

    bdev

    Joined:
    Jan 4, 2011
    Posts:
    656
    GUITexture.texture

    Change that on how you need to. If you know how to check for the click you would just do that there.
     
  5. g0tNoodles

    g0tNoodles

    Joined:
    Nov 28, 2010
    Posts:
    193
    Just what I needed, I managed to overlook that when looking through the script reference =/

    Thanks very much to you both!
     
  6. Deadguy71

    Deadguy71

    Joined:
    Jul 14, 2011
    Posts:
    10
    maybe you could use a light source that triggers on and off, thereby saving you texture loading?