A friend and I are trying to make a 2D game with depth. Essentially we'd like it so that if the Player were to walk behind the wall, the wall will render on top of the Player and if the Player were to walk in front of the wall, the wall would render behind the Player. Here's a GIF to show how it is now: Thanks guys!
I am working on this project with him and basically what I want to know is how to have a dynamic draw order between walls.
might be a pain to do but you could always have the wall as two separate images? one for the top and one for the bottom.
see isometric sorting: Code (CSharp): https://youtube.com/watch?v=rMCLWt1DuqI&feature=youtu.be&t=24m37s (example script download in description) It just adjusts sprite sorting order based on Y coordinate.. or ready asset with more features: http://forum.unity3d.com/threads/released-easy-isometric-sorting.322157/ *had to post youtube link as code, otherwise it embeds it..
I have made this. It sometimes works but sometimes, the z order is messed up if I move to a different area. Thanks for the help. Code (CSharp): using UnityEngine; using System.Collections; public class Depth : MonoBehaviour { private SpriteRenderer spriteRenderer; private GameObject shadow; private SpriteRenderer shadowSpriteRenderer; public void Start() { spriteRenderer = GetComponent<SpriteRenderer>(); shadow = GameObject.Find("Shadow"); shadowSpriteRenderer = shadow.GetComponent<SpriteRenderer>(); } public void Update() { spriteRenderer.sortingOrder = (int)transform.position.y * -1; shadowSpriteRenderer.sortingOrder = (int)transform.position.y * -1; } }
Thank you for this video, his method seems to work. The only issue is I'd have to make the Level through Unity itself rather than Tiled but that's ok with me as long as the method works haha