[Solved]Spawn GameObject according to the background

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;
}

You are getting the length of the array rather than the element so I think what you are trying to do here is something like this:

void Update()
{
    //if the 0 index background is enabled
    if(GetComponent<SpriteRenderer>().sprite == Backgrounds[0])
    {
        Luna.SetActive(true);
        Debug.Log("Sera");
    }


    //if the 1 index background is enabled
    if(GetComponent<SpriteRenderer>().sprite == Backgrounds[1])
    {
        Debug.Log("deserto");
    }


    //if the 2 index background is enabled
    if(GetComponent<SpriteRenderer>().sprite == Backgrounds[2])
    {
        Debug.Log("cielo");
    }
}

Consider storing the SpriteRenderer as a private variable and assigning it in start instead of using GetComponent every frame.

Thanks so much It is perfect