Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: eventropy on August 31, 2013, 05:45:41 PM

Title: Changing texture of sprite at runtime
Post by: eventropy on August 31, 2013, 05:45:41 PM
I want to apply a mouse over effect that changes the background texture of a UISprite, how would I go about this?
Title: Re: Changing texture of sprite at runtime
Post by: LightSky on August 31, 2013, 06:07:50 PM
public UISprite YourSprite;

void OnHover (bool isOver)  //Is called on any widget when you hover the cursor over it
{
    if(isOver) //If cursor is hovering
    {
       YourSprite.spriteName = "String name of your sprite in the same atlas" 
    }
    else
    {
       YourSprite.spriteName = "Previous name" 
    }
}

If you need to change the atlas just call  YourSprite.atlas and set it to whatever atlas you need.