How to load a scene after 10 objects

Hi, I have a question, how to load a scene if 10 objects are picked up ?
Here my script :

using UnityEngine;
using System.Collections;

public class PickUp : MonoBehaviour {
	
	public int nbStatuesFound = 0;
	public AudioClip pickSound;
	public Transform explosion;
	private GameObject toDestroy;
	private bool destroyObjectSwitch;
	private bool pickup;
	private bool collided;
	private int tempo;

	void Start () {
		this.destroyObjectSwitch = false;
		this.pickup = false;
		this.collided = false;

	}
	

	void Update () {
		if(Input.GetButton("Fire1")){
			this.pickup = true;
		}else{
			this.pickup = false;
			
		}
		
		Debug.Log ("pickup : "+this.pickup+" Collided : "+this.collided);
		
		if(this.pickup && this.collided){
			AudioSource.PlayClipAtPoint(pickSound, transform.position );
			Instantiate(explosion, transform.position, transform.rotation);
			Destroy(this.toDestroy.gameObject);
			this.nbStatuesFound++;	
			this.pickup = false;
			this.collided = false;
			this.tempo = 100;
				
			
			
		}
		
		if(this.tempo>0)this.tempo--;
		
		
	}
	
	
	void OnTriggerEnter(Collider other){
		Debug.Log (other.gameObject.name);
		if(other.gameObject.name == "Zombie" ){
			this.collided = true;
			this.toDestroy = other.gameObject;
		}
			
		
	}
	
	void OnTriggerExit(Collider other){
		this.collided = false;
		this.toDestroy = null;
	}
	
	void OnGUI(){
		if(this.tempo>0)
			GUI.Label (new Rect (Screen.width/2-100,Screen.height/2-10,200,20), "Vous en avez "+this.nbStatuesFound+" sur 10.");
		
		
	}
}

Thanks a lot :wink:

You need to call Application.loadLevel(“levelName”)

if (collectedObjects == 10)
{
   Application.loadLevel("levelName");
}

Be aware that this will destroy everything in your current scene so you will want to save anything you need to remember, or add a DoNotDestroy() to any objects you want to keep

Already try, it work but if i pick up only one object, he load my “WinScreen” :confused:

Already try, it work but if i pick up only one object, he load my “WinScreen” :confused:

That’s because you’re doing everything in Update. You set both states to true, and they every Update you will trigger the sequence, adding all 10 objects in 10 frames.

You want to add the object in the MouseClick code, and use “GetButtonDown” as that will only activate once, rather than repeatedly as the “GetButton” will do.

if (Input.GetMouseButtonDown(0) && this.collided == true)
{
    AudioSource.PlayClipAtPoint(pickSound, transform.position );
    Instantiate(explosion, transform.position, transform.rotation);
    Destroy(this.toDestroy.gameObject);
    this.nbStatuesFound++;   
    this.pickup = false;
    this.collided = false;
    this.tempo = 100;   
}

Does that work?

Yes, I see what is my mistake now !
Thanks a lot !!!
By the way, if I want to launch a movie at the place of the “Winscreen”
Ho i can do this ?
I have Unity Pro.