I’m creating a random background spawner, now if the spawned background is 0 ,I would a certain gameobject is activited in the scene.I tried this but in unsecessful .Any Ideas?
using UnityEngine;
using System.Collections;
public class RandomBackgroundScript : MonoBehaviour {
public GameObject Luna;
// Use this for initialization
void Start () {
(GetComponent<Renderer>() as SpriteRenderer).sprite = Backgrounds[Random.Range(0, Backgrounds.Length)];
}
// Update is called once per frame
void Update () {
foreach(SpriteRenderer Sfondo in Backgrounds)
{
if (Backgrounds.Length==0) {
Luna.SetActive (true);
Debug.Log ("Sera");
}
if (Backgrounds.Length==1) {
Debug.Log ("deserto");
}
if (Backgrounds.Length==2) {
Debug.Log ("cielo");
}
}
}
public Sprite[] Backgrounds;
}