Sorry for throwing this question just like that upon you, project has to be done in 3 hours and I still have a lot to do.
I have made a script which randomly places “Coins(Clone)” on map about 25 times, but I need to change it’s layer of order to 1. Worth noting that these instances are made out of prefab and don’t exist before the game is started.
How can I do that? Sorry for throwing this question once again, I could make invesitgation but, there’s still lot to do.
when you instantiate, set the layer of the gameobject.
var coin = Object.Instantiate(coinPrefab) as GameObject;
coin.layer = 1;
I’m assuming you mean the layer property on the GameObject used for Physics and Camera rendering… if you’re talking about some other layer, you’ll need to define what layer you’re talking about.
1 Like
I meant “Sprite Renderer > Order in Layer”
But thank you for your very fast response and help. (still need the working one though )
Is the SpriteRenderer on the root of the prefab?
If so, get the SpriterRenderer off of it and set the ‘sortingOrder’ (that’s the actual property you’re looking for).
var coin = Object.Instantiate(coinPrefab) as GameObject;
var renderer = coin.GetComponent<SpriteRenderer>(); //if it's on a child, you'll need to find the child first
renderer.sortingOrder = 1;
Is there a reason the prefab can’t have it set to 1 in the first place???
1 Like
Is the SpriteRenderer on the root of the prefab?
(facepalm) I’m an idiot… I could’ve just set Prefab to Layer 1… and copies will inherit it… oh man… sorry for wasting your time. Thank you for your responses.