i am making my first space shooter game, i need help with changing to the next scene after all the asteroids are destroyed.
my asteroid script is
using UnityEngine;
using System.Collections;
public class AsteroidScript : MonoBehaviour
{
public float MinTorque = -100f;
public float MaxTorque = 100f;
public float MinForce = 20f;
public float MaxForce = 40f;
public GameObject Explosion;
public GameObject ChildAsteroid;
public int NumChildAsteroids = 2;
// Use this for initialization
void Start ()
{
float magnitude = Random.Range (MinForce, MaxForce);
float x = Random.Range (-1f, 1f);
float y = Random.Range (-1f, 1f);
rigidbody2D.AddForce (magnitude * new Vector2 (x, y));
float torque = Random.Range (MinTorque, MaxTorque);
rigidbody2D.AddTorque (torque);
}
void Update()
{
}
void OnTriggerEnter2D(Collider2D collider)
{
if (collider.gameObject.tag == "ShipBullet")
{
Instantiate (Explosion, transform.position, new Quaternion ());
Destroy (collider.gameObject);
Destroy (gameObject);
if (ChildAsteroid != null)
{
for (int i = 0; i < NumChildAsteroids; i++)
{
Instantiate(ChildAsteroid, transform.position, new Quaternion());
}
}
}
}
}
and my spaceship script is
using UnityEngine;
using System.Collections;
public class ShipScript : MonoBehaviour {
public float RotationSpeed;
public float ThrustForce;
public ParticleSystem ThrustParticleEffect;
public AudioSource ThrustAudioSource;
public GameObject BulletPrefab;
public GameObject ShipExplosion;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown (KeyCode.Space))
{
Instantiate(BulletPrefab, transform.position, transform.rotation);
}
}
void FixedUpdate()
{
if (Input.GetKey (KeyCode.LeftArrow))
{
//Rotate ship to the left.
rigidbody2D.angularVelocity = RotationSpeed;
}
else if (Input.GetKey (KeyCode.RightArrow))
{
//Rotate ship to the right.
rigidbody2D.angularVelocity = -RotationSpeed;
}
else
{
//Stop Rotation.
rigidbody2D.angularVelocity = 0f;
}
if (Input.GetKey (KeyCode.UpArrow))
{
//Engage the engine.
Vector2 forceVector = transform.up * ThrustForce;
rigidbody2D.AddForce (forceVector);
// show thrust particle effect.
ThrustParticleEffect.Play ();
//play thrust sound.
if (ThrustAudioSource.isPlaying ==false) ThrustAudioSource.Play();
}
else
{
//end the particle effect.
ThrustParticleEffect.Stop ();
//end the thrust sound.
ThrustAudioSource.Stop();
}
}
void OnTriggerEnter2D(Collider2D collider)
{
if (collider.gameObject.tag == "Asteroid") {
Instantiate (ShipExplosion, transform.position, new Quaternion ());
Destroy (gameObject);
} else if (collider.gameObject.tag == "Alien" || collider.gameObject.tag == "AlienBullet")
{
Destroy (gameObject);
Destroy (collider.gameObject);
Instantiate(ShipExplosion, transform.position, new Quaternion());
}
}
}
any help is appreciated.