Hello,
I am trying to figure out the best & most efficient way to set/change a game object's sorting layer on the fly using PlayMaker.
Here is the scenario:
- This is for a system of clickable powerups in an arcade-style, single-screen 2D game.
- There are 4 types of powerups, chosen at random at a regular interval.
- When the powerup is randomly selected, it is stored in a GameObject variable for later reference.
- One of four valid screen locations is then selected, also at random.
- Two locations are at the top of the screen, two are at the bottom.
- In order to sort correctly with the other actors on screen, I need the objects at the top to be on one sorting layer and the objects at the bottom to be on another sorting layer.
The problem:
- I want to change the sorting layer of the spawned powerup at the time it is spawned, based on its randomly selected spawn location.
- I assumed I could do this using Set Property, and sure enough there is a Renderer/sortingLayerName property available if I drag a game object or prefab into the target field for that action.
- However, if I try to use the gameobject variable I mentioned above, it does not work. When I flip the target field of the Set Property action over to variable, it only support Object variables, not GameObject.
- So as far as I can tell, I can only change the sorting layer on a specific target gameobject or prefab, and not on a gameobject variable.
FWIW - The powerups are being spawned through PoolManager 5, but I could also simply spawn prefabs without any pool management & have the same issue.
I know I can make an FSM to do what I want here, just by using some redundant structures for each possible powerup and/or screen location. Or possibly by just making "Top" and "Bottom" variants of each powerup. I was hoping to keep it simple, efficient, and streamlined, though, so I am wondering if there's another option I am missing?
I hope this all makes sense.