I am trying to make an Endless Runner game with some spawners but I am having some problems.
As the Sprites are from different sizes, some of them are getting on top of others (like the image attached).
What I am trying to do is: When my spawner chooses the Prefab that is going to be Instantiated from an Array of 7 Obstacles, the newly spawned prefab will change it Sorting Layer so that the top lane of obstacles are put behind the middle one and the last (bottom) is in front of all other, so with that the sprites won’t be like what is happening on the screenshot.
The code that I have so far is this one:
using UnityEngine;
using System.Collections;
public class ObstacleDown : MonoBehaviour {
public GameObject[] obstacles;
// Use this for initialization
void Start () {
Instantiate (obstacles [Random.Range (0, 6)], new Vector3(3.5f,0.1f,-0.5f), Quaternion.identity);
}
// Update is called once per frame
void Update () {
}
}
Does anyone knows how to change this? If I didn’t made myself clear or you need any more info, please ask.
Thanks a lot!!