// Update is called once per frame void Update() { //Spawn static tree if T-Key has been pressed if (Input.GetKeyDown(KeyCode.T)) { Vector3 spawnPos = spawnPoint.transform.position; GameObject tree = Instantiate(treePrefab, spawnPos, Quaternion.identity); sorter.sortOnce(tree.GetComponent <SpriteRenderer>()); //Sort this new static GameObject (tree) once } //Spawn chasing scarecrow if G-Key has been pressed if (Input.GetKeyDown(KeyCode.G)) { Vector3 spawnPos = spawnPoint.transform.position; GameObject scarecrow = Instantiate(enemyPrefab, spawnPos, Quaternion.identity); sorter.registerRenderer(scarecrow.GetComponent <SpriteRenderer>()); //Registering dynamic/moving GameObject (Scarecrow) } }
// Start is called before the first frame update void Start() { sorter = FindObjectOfType <SpriteSorter>(); player = Instantiate(player, startPos.transform.position, Quaternion.identity); sorter.registerRenderer(player.GetComponent <SpriteRenderer>()); }