Switching Z Depths at runtime

I’ve been searching tinkering away but still am unable to influence a game object’s z-depth at runtime.

I want to be able to have an object in front of another but appear to move behind the object, like hiding for example.

I have the two objects on separate layers but on the same sorting layer with different z-depth values.

I’ve been looking at manipulating the game object’s Sprite Renderers but so far nuthin…:o

Can any of you more experienced geezers point me in the right direction please?

I don’t really understand what you’re trying to say here…

In code I’m switching a game object’s SpriteRenderer.sortingOrder SpriteRenderer.sortingLayerName in the attempt to make one game object start off in front of another game object but then appear behind that same other game object if say, i click a button.

Use Transform.position.z or Transform.position

Thanks, cbothra. Just realized that i was manipulating the control button not the actual object! (stupid).
I’m getting the values to change but the visual result isn’t happening, one object is not going behind another…
I’ll keep hacking, thanks again :slight_smile:

Got it working by manipulating the SpriteRenderer.sortingOrder. :stuck_out_tongue: