2D Toolkit Forum
2D Toolkit => Support => Topic started by: neo750a on December 28, 2013, 01:24:57 am
-
Is this possible? Or do i have to make a database myself and store prefabs to achieve this? It would be immensely helpful if I could as it would cut out alot of what I need done. What I am trying to do is to display 6 different sprites on 6 random points(one unique sprite each point) on the game view. Thanks in advance and sorry if this was asked previously.
-
Create a prefab of a sprite from the sprite collection, instantiate it and then change the sprite Id using something like this:
int randomSprite = 0;
do {
randomSprite = Random.Range(0, sprite.Collection.Count);
} while (!sprite.Collection.spriteDefinitions[randomSprite].Valid);
sprite.SetSprite( randomSprite);
the while loop is necessary in case you have deleted / invalid sprites in your collection.
-
Create a prefab of a sprite from the sprite collection, instantiate it and then change the sprite Id using something like this:
int randomSprite = 0;
do {
randomSprite = Random.Range(0, sprite.Collection.Count);
} while (!sprite.Collection.spriteDefinitions[randomSprite].Valid);
sprite.SetSprite( randomSprite);
the while loop is necessary in case you have deleted / invalid sprites in your collection.
I have to say, thank very much for the response! Sorry for the long reply. This helped me out immensely!