Last updated
Last updated
This code can be attached to a gameObject that has a spriteRenderer, it will allow creation of a list of sprites that can be changed by calling the swapSprite( ) method.
The image below shows the BackgroundImage GameObject, where the ChangeSprite Script has been added as a script component. Here we can see that the spriteList in the inspector has been set to hold 4 elements, then when expanded, the 4 slots have been populated with different sprites that can be swapped out for the background image.
public void swapSprite( ) has been declared as a public method so that it can be called from the LevelManager: In order to do that, the LevelManager must create an objectReference to the ChangeSprite Script: