diff options
| author | Simon O'Shea <osheas1@wit.edu> | 2023-07-31 18:45:01 -0400 |
|---|---|---|
| committer | Simon O'Shea <osheas1@wit.edu> | 2023-07-31 18:45:01 -0400 |
| commit | 5f9e8f979deb94e9219113ed09b49142c040cb57 (patch) | |
| tree | a67bd606205f7fb28e48d351028b3478bc49145b /Pathfinding Visualizer/Assets/CodeMonkey/MonoBehaviours/PositionRendererSorter.cs | |
| parent | 4699ce72871eaa6ee27c01971383b9d1fced1946 (diff) | |
import successful, grid has visuals
cell values and grid lines are displayed. no interaction available yet.
Diffstat (limited to 'Pathfinding Visualizer/Assets/CodeMonkey/MonoBehaviours/PositionRendererSorter.cs')
| -rw-r--r-- | Pathfinding Visualizer/Assets/CodeMonkey/MonoBehaviours/PositionRendererSorter.cs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/Pathfinding Visualizer/Assets/CodeMonkey/MonoBehaviours/PositionRendererSorter.cs b/Pathfinding Visualizer/Assets/CodeMonkey/MonoBehaviours/PositionRendererSorter.cs new file mode 100644 index 0000000..46f2058 --- /dev/null +++ b/Pathfinding Visualizer/Assets/CodeMonkey/MonoBehaviours/PositionRendererSorter.cs @@ -0,0 +1,51 @@ +/* + ------------------- Code Monkey ------------------- + + Thank you for downloading the Code Monkey Utilities + I hope you find them useful in your projects + If you have any questions use the contact form + Cheers! + + unitycodemonkey.com + -------------------------------------------------- + */ + +using UnityEngine; + +namespace CodeMonkey.MonoBehaviours { + + /* + * Automatically sort a Renderer (SpriteRenderer, MeshRenderer) based on his Y position + * */ + public class PositionRendererSorter : MonoBehaviour { + + [SerializeField] private int sortingOrderBase = 5000; // This number should be higher than what any of your sprites will be on the position.y + [SerializeField] private int offset = 0; + [SerializeField] private bool runOnlyOnce = false; + + private float timer; + private float timerMax = .1f; + private Renderer myRenderer; + + private void Awake() { + myRenderer = gameObject.GetComponent<Renderer>(); + } + + private void LateUpdate() { + timer -= Time.deltaTime; + if (timer <= 0f) { + timer = timerMax; + myRenderer.sortingOrder = (int)(sortingOrderBase - transform.position.y - offset); + if (runOnlyOnce) { + Destroy(this); + } + } + } + + public void SetOffset(int offset) { + this.offset = offset; + } + + } + +}
\ No newline at end of file |
