public GetSprite ( string name ) : UISpriteData, | ||
name | string | |
return | UISpriteData, |
UIAtlas myAtlas = Resources.Load("MyAtlas"); // Get the "Logo" sprite from the atlas UISpriteData logoSprite = myAtlas.GetSprite("Logo"); // Set the sprite for a UISprite component GetComponent ().spriteName = logoSprite.name;
UIAtlas myAtlas = GetComponentThis example retrieves an atlas component attached to the same GameObject and gets a random sprite from the atlas using the GetListOfSprites method. The sprite data is then used to set the sprite for a UI2DSprite component. Package Library: The UIAtlas class and the GetSprite method are part of the NGUI package.(); // Get a random sprite from the atlas UISpriteData[] sprites = myAtlas.GetListOfSprites().ToArray(); UISpriteData randomSprite = sprites[Random.Range(0, sprites.Length)]; // Set the sprite for a UI2DSprite component GetComponent ().sprite2D = myAtlas.GetSprite(randomSprite.name).texture;
public GetSprite ( string name ) : UISpriteData, | ||
name | string | |
return | UISpriteData, |