- Home /
Prefabs and multiple tilesets?
I have created a bunch of prefabs from a tileset to build a map. Since my tileset layout will be the same I do not want to create prefabs for each tileset but just switch the main tileset/sheet and use the same source coordinate from that sheet. How would I do that?
Since SpriteRenderer
just uses the actual sprite that is already cut up I cannot switch the complete sheet which is limiting me. One way I could think of would be to replace the string before _XX
and put in the name of the other sheet but this feels kind of hacky.
Otherwise I might have to setup the complete sheet in code so I can set the initial sheet to use but I rather change my prefabs since these are a lot more then a GameObject
with a sprite attached to it.
Following code just gets me the first sprite if I dump the complete sheet in the newSprite
slot.
public Sprite newSprite;
void Awake () {
foreach (SpriteRenderer sr in gameObject.GetComponentsInChildren<SpriteRenderer>())
{
sr.sprite = newSprite;
}
}
Let's say for level 1 I want to use tileset01
and a floor tile could be tileset01_08
. For level 2 I want to use tileset02
and that same floor tile should be tileset02_08
. And I want a flexible way to replace complete sets.