Exemplo n.º 1
0
    // id: 0 = Speed 1 (small plane), 1 = Speed 2 (normal plane), 2 = Speed 3 (fast plane)
    private void SpawnPlane()
    {
        CalculateLevel();
        if (AllowSound)
        {
            audioSource.clip = radarClip;
            audioSource.Play();
        }
        int[] tempSP = new int[4] {
            -1, -1, -1, -1
        };

        for (int i = 0; i < maxSpawnPlaneAmount; i++)
        {
            int sp;

            if (spawnStartPlane > -1)
            {
                switch (spawnStartPlane)
                {
                case 0:
                    ampel01.material = ampelLights[0];
                    AmpelSpawnR.SetActive(false);
                    break;

                case 1:
                    ampel02.material = ampelLights[0];
                    AmpelSpawnL.SetActive(false);
                    break;
                }

                int planeType;
                planeType = Random.Range(0, maxSpawnPlaneSize);
                GameObject      planeObject = Instantiate(planePrefab[planeType], allStartSpawnpoints[spawnStartPlane].position, allStartSpawnpoints[spawnStartPlane].rotation, transform);
                PlaneController plane       = planeObject.GetComponent <PlaneController>();
                plane.PlaneSetup(this, mapBorders, ShowFeedback, AllowSound, spawnStartPlane, possibleDestinations, true);
                allPlanes.Add(plane);

                if (startPlaneOnSpawnPoints[spawnStartPlane])
                {
                    plane.PlayeExplosion();
                    CrashStarted(plane.transform.position, plane.transform.forward);
                    StartCoroutine(EndGameAfterTime());
                }
                else
                {
                    startPlaneOnSpawnPoints[spawnStartPlane] = true;
                    spawnStartPlane = -1;
                }
            }
            else
            {
                do
                {
                    sp = Random.Range(0, allSpawnpoints.Length);
                } while (sp == lastSpawnPoints[0] || sp == lastSpawnPoints[1] || sp == lastSpawnPoints[2] || sp == lastSpawnPoints[3] || sp == tempSP[0] || sp == tempSP[1] || sp == tempSP[2] || sp == tempSP[3]);
                tempSP[i] = sp;
                int planeType;
                planeType = Random.Range(0, maxSpawnPlaneSize);
                GameObject      planeObject = Instantiate(planePrefab[planeType], allSpawnpoints[sp].position, allSpawnpoints[sp].rotation, transform);
                PlaneController plane       = planeObject.GetComponent <PlaneController>();
                plane.PlaneSetup(this, mapBorders, ShowFeedback, AllowSound, -1);
                allPlanes.Add(plane);
            }
        }

        lastSpawnPoints = tempSP;

        if (allStartSpawnpoints.Length > 0)
        {
            float number = Random.Range(0, 100);
            if (number < startplaneSpawnChance)
            {
                if (startPlaneOnSpawnPoints[0] && startPlaneOnSpawnPoints[1])
                {
                    int id = Random.Range(0, allStartSpawnpoints.Length);
                    spawnStartPlane = id;
                    switch (id)
                    {
                    case 0:
                        ampel01.material = ampelLights[1];
                        AmpelSpawnR.SetActive(true);
                        break;

                    case 1:
                        ampel02.material = ampelLights[1];
                        AmpelSpawnL.SetActive(true);
                        break;
                    }
                }
                else if (startPlaneOnSpawnPoints[0])
                {
                    spawnStartPlane  = 1;
                    ampel02.material = ampelLights[1];
                    AmpelSpawnL.SetActive(true);
                }
                else
                {
                    spawnStartPlane  = 0;
                    ampel01.material = ampelLights[1];
                    AmpelSpawnR.SetActive(true);
                }
            }
        }
    }