Example #1
0
    public float ranAttack;                             // stores the random time until the next enemy2 is instantiated.

    void Start()                                        // *** Setting up the game.. ***
    {
        gameStart1 = false;                             // setting the ints and bools..
        gameStart2 = false;
        ships      = 0;
        totalShips = 1;
        gameOver   = false;
        restart    = false;

        restartText.text  = "";                                                 // setting up the guitexts..
        gameOverText.text = "Cross the Asteroid Field -> -> \n Then Reduce Velocity to < 100 m/s";
        playerVel.text    = "Velocity: ";

        playerControllerMS      = motherShip.GetComponent <PlayerControllerMS> ();
        playerControllerFighter = fighter1.GetComponent <PlayerControllerFighter> ();

        int ran = Random.Range(0, 4);                                   // randomly choosing 1 of 4 Metallica songs..

        if (ran == 0)
        {
            GetComponent <AudioSource>().Play();
        }
        if (ran == 1)
        {
            track.GetComponent <AudioSource>().Play();
        }
        if (ran == 2)
        {
            track1.GetComponent <AudioSource>().Play();
        }
        if (ran == 3)
        {
            track2.GetComponent <AudioSource>().Play();
        }

        while (hazards1 > 0)                                    // randomly spawning the asteroids into middle(hazards1), left(hazards2) and right(hazards3) quadrants.
        {
            if (hazards1 > 0)
            {
                Vector3    spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, Random.Range(40.0f, spawnValues.z));
                Quaternion spawnRotation = Quaternion.Euler(0.0f, Random.Range(0.0f, 360.0f), 0.0f);
                Instantiate(hazard, spawnPosition, spawnRotation);
            }
            hazards1 -= 1;
        }
        while (hazards2 > 0)
        {
            if (hazards2 > 0)
            {
                Vector3    spawnPosition = new Vector3(Random.Range(-spawnValues.x - 55.0f, spawnValues.x - 55.0f), spawnValues.y, Random.Range(40.0f, spawnValues.z));
                Quaternion spawnRotation = Quaternion.Euler(0.0f, Random.Range(0.0f, 360.0f), 0.0f);
                Instantiate(hazard, spawnPosition, spawnRotation);
            }
            hazards2 -= 1;
        }
        while (hazards3 > 0)
        {
            if (hazards3 > 0)
            {
                Vector3    spawnPosition = new Vector3(Random.Range(-spawnValues.x + 55.0f, spawnValues.x + 55.0f), spawnValues.y, Random.Range(40.0f, spawnValues.z));
                Quaternion spawnRotation = Quaternion.Euler(0.0f, Random.Range(0.0f, 360.0f), 0.0f);
                Instantiate(hazard, spawnPosition, spawnRotation);
            }
            hazards3 -= 1;
        }

        ranAttack = Random.Range(30, 70) + Time.time;                                   // sets the time until enemy2 spawns to a random int between 30 and 69 seconds.
    }
    // *** Setting up the game.. ***
    void Start()
    {
        gameStart1 = false;							// setting the ints and bools..
        gameStart2 = false;
        ships = 0;
        totalShips = 1;
        gameOver = false;
        restart = false;

        restartText.text = "";						// setting up the guitexts..
        gameOverText.text = "Cross the Asteroid Field -> -> \n Then Reduce Velocity to < 100 m/s";
        playerVel.text = "Velocity: ";

        playerControllerMS = motherShip.GetComponent<PlayerControllerMS> ();
        playerControllerFighter = fighter1.GetComponent<PlayerControllerFighter> ();

        int ran = Random.Range (0, 4);				// randomly choosing 1 of 4 Metallica songs..
        if (ran == 0) {
            GetComponent<AudioSource>().Play();
        }
        if (ran == 1) {
            track.GetComponent<AudioSource>().Play();
        }
        if (ran == 2) {
            track1.GetComponent<AudioSource>().Play();
        }
        if (ran == 3) {
            track2.GetComponent<AudioSource>().Play();
        }

        while (hazards1 > 0) {				// randomly spawning the asteroids into middle(hazards1), left(hazards2) and right(hazards3) quadrants.
            if (hazards1 > 0) {
                Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), spawnValues.y, Random.Range (40.0f, spawnValues.z));
                Quaternion spawnRotation = Quaternion.Euler (0.0f, Random.Range (0.0f, 360.0f), 0.0f);
                Instantiate (hazard, spawnPosition, spawnRotation);
            }
            hazards1 -= 1;
        }
        while (hazards2 > 0) {
            if (hazards2 > 0) {
                Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x - 55.0f, spawnValues.x - 55.0f), spawnValues.y, Random.Range (40.0f, spawnValues.z));
                Quaternion spawnRotation = Quaternion.Euler (0.0f, Random.Range (0.0f, 360.0f), 0.0f);
                Instantiate (hazard, spawnPosition, spawnRotation);
            }
            hazards2 -= 1;
        }
        while (hazards3 > 0) {
            if (hazards3 > 0) {
                Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x + 55.0f, spawnValues.x + 55.0f), spawnValues.y, Random.Range (40.0f, spawnValues.z));
                Quaternion spawnRotation = Quaternion.Euler (0.0f, Random.Range (0.0f, 360.0f), 0.0f);
                Instantiate (hazard, spawnPosition, spawnRotation);
            }
            hazards3 -= 1;
        }

        ranAttack = Random.Range (30, 70) + Time.time;				// sets the time until enemy2 spawns to a random int between 30 and 69 seconds.
    }