Beispiel #1
0
        //Поиск целей и их сортировка
        void testCar()
        {
            //Если тест не завешен то выполняем
            if (!testEnd && collider != null && Time.deltaTime < 0.2f)
            {
                //вытаскиваем колайдеры если их нет
                if (collider == null || collider.Length <= 0)
                {
                    collider = Physics.OverlapSphere(positionBoom, 9000);
                }

                //Если колайдеры не прошли тест
                else if (!testColiderEnd)
                {
                    //Проверяем колайдеры на автомобиль
                    for (int num = 0; numColiderTest < collider.Length && num < maxTesting; numColiderTest++, num++)
                    {
                        //Вытаскиваем из колайдера автомобиль
                        CarStatic carStaticNow = null;
                        if (collider[numColiderTest] != null)
                        {
                            carStaticNow = collider[numColiderTest].GetComponent <CarStatic>();
                        }

                        if (carStaticNow != null)
                        {
                            SumAutofound++;
                        }

                        //Если это последняя проверка то завершаем
                        if (collider.Length == numColiderTest + 1)
                        {
                            testColiderEnd = true;
                        }
                    }
                }


                //Если все автомобили не были найдены
                else if (!CarFound)
                {
                    //Если еще не создан массив
                    if (carStatics == null)
                    {
                        //Создаем массив
                        carStatics     = new CarStatic[SumAutofound];
                        numColiderTest = 0;
                        numCarTest     = 0;
                    }
                    else
                    {
                        //Снова перебираем массив колайдера но на этот раз запоминаем автомобиль
                        for (int num = 0; numColiderTest < collider.Length && num < maxTesting; numColiderTest++, num++)
                        {
                            //Вытаскиваем из колайдера автомобиль
                            CarStatic carStaticNow = null;
                            if (collider[numColiderTest] != null)
                            {
                                carStaticNow = collider[numColiderTest].GetComponent <CarStatic>();
                            }

                            if (carStaticNow != null)
                            {
                                //вытаскиваем автомобиль
                                carStatics[numCarTest] = carStaticNow;
                                numCarTest++;
                            }


                            //Если это последняя проверка то завершаем
                            if (collider.Length == numColiderTest + 1 || carStatics.Length == numCarTest + 1)
                            {
                                CarFound = true;
                            }
                        }
                    }
                }
                //Если нужно отсортировать
                else if (!CarSort)
                {
                    CarStatic carStaticTime;

                    //продолжаем сортировку со старого места
                    for (int num = 0; numSort < carStatics.Length && num < maxTesting; num++, numSort++)
                    {
                        float DistNow = 999999;
                        if (carStatics[numSort] != null)
                        {
                            DistNow = Vector3.Distance(positionBoom, carStatics[numSort].gameObject.transform.position);
                        }

                        //начинаем сравнивать настоящий номер с остальными
                        for (int numTest = numSort; numTest < carStatics.Length; numTest++)
                        {
                            //Получаем растояние до обьектов
                            float DistTest = 999999;
                            if (carStatics[numTest] != null)
                            {
                                Vector3.Distance(positionBoom, carStatics[numTest].gameObject.transform.position);
                            }

                            //Если сравниваемый номер меньше сравниваемого настоящего
                            if (DistTest < DistNow)
                            {
                                //Значит меняем их местами
                                //Запоминаем настоящий
                                carStaticTime = carStatics[numSort];
                                //Ставим тестируемый на место настоящего
                                carStatics[numSort] = carStatics[numTest];
                                //Ставим запомненый на место тестируемого
                                carStatics[numTest] = carStaticTime;

                                //Замена выполнена
                            }
                        }
                    }
                    //Говорим что сортировка завершена
                    CarSort = true;
                }
                //Если все тесты пыполнены а это не указано то завершаеим
                else if (!testEnd)
                {
                    testEnd = true;
                }
            }
        }
Beispiel #2
0
    //Убийство цели
    public void DeathTarget()
    {
        if (heath > 0)
        {
            heath = 0;
        }

        achievement.plus_1_destroy_object();
        player_save.PlusCombo();

        //Уменьшаем вес
        Rigidbody rigidbody = gameObject.GetComponent <Rigidbody>();

        if (rigidbody != null)
        {
            //Размораживаем
            rigidbody.constraints = RigidbodyConstraints.None;
        }

        HingeJoint hingeJoint = gameObject.GetComponent <HingeJoint>();

        if (hingeJoint != null)
        {
            GameObject.Destroy(hingeJoint);
        }

        //Если есть частицы смерти
        if (particleDie != null)
        {
            particleDie.Play();
        }

        //Воспросизводим звук смерти
        TargetSound sounds = gameObject.GetComponent <TargetSound>();

        if (sounds != null)
        {
            gameObject.GetComponent <TargetSound>().PlaySoundDestroy();
        }

        //Спавним обьект после смерти
        if (ObjSpawnDie != null)
        {
            GameObject DieObj = Instantiate(ObjSpawnDie, gameObject.transform.parent);
            DieObj.transform.position = gameObject.transform.position;
        }

        //Если это постройка
        BildTarget bild = gameObject.GetComponent <BildTarget>();

        if (bild != null)
        {
            bild.need_destroy = true;
        }
        //Если цель автомобиль
        CarStatic CarSiren = gameObject.GetComponent <CarStatic>();

        if (CarSiren != null)
        {
            CarSiren.OffSignal();
        }

        //Если это автомобиль
        Automobile automobile = gameObject.GetComponent <Automobile>();

        if (automobile != null && rigidbody != null)
        {
            rigidbody.mass = rigidbody.mass / 100;

            police_car police = gameObject.GetComponent <police_car>();
            if (police != null && achievement != null)
            {
                achievement.plus_1_destroy_police();
            }
        }

        //Если это танк
        Tank tank = gameObject.GetComponent <Tank>();

        if (tank != null)
        {
            tank.BrokenTank();
        }
        //Если это пуля танка
        TankBullet tankBullet = gameObject.GetComponent <TankBullet>();

        if (tankBullet != null)
        {
            tankBullet.testBoom = true;
        }

        flyer fly = gameObject.GetComponent <flyer>();

        if (fly != null && achievement != null)
        {
            achievement.destroy_fighter();
        }

        //Взрываем
        BoomTarget boom = gameObject.GetComponent <BoomTarget>();

        if (boom != null)
        {
            boom.BOOM();
        }

        //Убиваем все дочерние обьекты
        //PiiTarget[] piiTargets = gameObject.GetComponentsInChildren<PiiTarget>();
        //if (piiTargets != null) {
        //    for (int num = 0; num < piiTargets.Length; num++) {
        //        if (piiTargets[num] != gameObject.GetComponent<PiiTarget>()) {
        //            piiTargets[num].DeathTarget();
        //        }
        //   }
        //}

        //убиваем все дочерние обьекты по новому
        if (SiskoTarget != null && SiskoTarget.Length != 0)
        {
            for (int x = 0; x < SiskoTarget.Length; x++)
            {
                if (SiskoTarget[x] != null && SiskoTarget[x].heath > 0)
                {
                    SiskoTarget[x].DeathTarget();
                }
            }
        }
    }
Beispiel #3
0
    public void TrigerPii(float presure, FaceController faceController, PiiController piiController, GameObject score_Text_func)
    {
        //Если у мочи достаточно инерции и если у предмета еще есть здоровье
        if (presure >= MinPresure && heath != 0)
        {
            float score_plus_now = 0;

            if (heath > 0)
            {
                //Сперва проверяем напрягся ли игрок
                if (player_save != null && player_save.bolt.GetComponent <PiiController>().ChargeOn)
                {
                    heath -= presure;
                    if (!gameplayParametrs.GameOver)
                    {
                        score_plus_now = score * 1.5f;
                        player_save.PlusScore(score_plus_now);
                    }
                }
                else if (player_save != null && !player_save.bolt.GetComponent <PiiController>().ChargeOn)
                {
                    score_plus_now = score;
                    player_save.PlusScore(score_plus_now);
                }
                heath -= presure;

                if (heath < 0)
                {
                    heath = 0;
                }
                heath_percent = heath / (start_heath / 100);
                //Если есть частицы то воспроизводим их
                if (particle != null)
                {
                    particle.Play();
                }

                SetColorNeed(heath_percent);

                //Если здоровье закончилось
                if (heath <= 0)
                {
                    DeathTarget();
                    test_lvl_target(player_save.gameplayParametrs);

                    score_plus_now = score * score_destroy;
                    player_save.PlusScore(score_plus_now);

                    if (faceController != null && fear_emotion_dead && Random.Range(0, 100) < 50)
                    {
                        faceController.set_fear(3f);
                    }

                    helicopter helicopterObj = gameObject.GetComponent <helicopter>();
                    if (helicopterObj != null)
                    {
                        player_save.SetFullCharge();
                    }
                }
                //Иначе звук попадания
                else
                {
                    //Воспросизводим звук попадания
                    TargetSound sounds = gameObject.GetComponent <TargetSound>();
                    if (sounds != null)
                    {
                        gameObject.GetComponent <TargetSound>().PlaySoundPii();
                    }

                    //Если цель автомобиль воспроизводим сигнализацию
                    CarStatic CarSiren = gameObject.GetComponent <CarStatic>();
                    if (CarSiren != null)
                    {
                        CarSiren.StartSignal();
                    }
                    //Если цель полиция то запускаем сирену
                    police_car police = gameObject.GetComponent <police_car>();
                    if (police != null && !police.police_active_now)
                    {
                        police.police_active_now = true;
                        police.need_sound_yn     = true;
                    }
                }
            }

            if (faceController != null && !piiController.ChargeOn)
            {
                if (Random.Range(0, 100) < 1.1f)
                {
                    faceController.set_bliss_voice(1.2f);
                }
                if (Random.Range(0, 100) < 0.1f)
                {
                    faceController.set_surprise_voice(1.2f);
                }

                if (Random.Range(0, 100) < 0.1f && fear_emotion)
                {
                    faceController.set_choked_voice();
                }
            }


            if (score_Text_func != null)
            {
                if (score_text != null)
                {
                    GameObject.Destroy(score_text);
                }

                score_text = Instantiate(score_Text_func);
                Score_text_3d score_Text_3D = score_text.GetComponent <Score_text_3d>();

                ScoreSum += score_plus_now;
                //Проверка того что нужно написать в зависимости от здоровья
                if (heath > 0)
                {
                    Color color_new = new Color(1f, 0.92f, 0, 0.62f);
                    score_Text_3D.inicialize(player_save.gameObject, ((int)heath_percent).ToString() + "%", gameObject.transform.position, color_new);
                }
                else
                {
                    Color color_new = new Color(1f, 0.47f, 0, 0.62f);
                    score_Text_3D.inicialize(player_save.gameObject, ((int)ScoreSum).ToString(), gameObject.transform.position, color_new);
                }
            }
        }
    }
    //Спавнить автомобиль
    void Spawn()
    {
        bool spawn_ok = false;

        while (!spawn_ok)
        {
            int        type = Random.Range(0, 4);
            GameObject car  = null;

            if (type == 0 && void_ver > Random.Range(0, 100))
            {
                spawn_ok = true;
            }
            else if (type == 1 && police_ver > Random.Range(0, 100) && cars_police.Length != 0 && police == true)
            {
                car      = Instantiate(cars_police[Random.Range(0, cars_police.Length)], gameObject.transform);
                spawn_ok = true;
            }
            else if (type == 2 && legkovaya_ver > Random.Range(0, 100) && cars_legkovay.Length != 0 && legkovaya == true)
            {
                car      = Instantiate(cars_legkovay[Random.Range(0, cars_legkovay.Length)], gameObject.transform);
                spawn_ok = true;
            }
            else if (type == 3 && gruzovaya_ver > Random.Range(0, 100) && cars_gruzovay.Length != 0 && gruzovaya == true)
            {
                car      = Instantiate(cars_gruzovay[Random.Range(0, cars_gruzovay.Length)], gameObject.transform);
                spawn_ok = true;
            }
            else if (type == 4 && avtobuss_ver > Random.Range(0, 100) && cars_avtobuss.Length != 0 && avtobuss == true)
            {
                car      = Instantiate(cars_avtobuss[Random.Range(0, cars_avtobuss.Length)], gameObject.transform);
                spawn_ok = true;
            }

            if (car != null)
            {
                //вытаскиваем длину
                //наХОДИМ все боксы
                BoxCollider[] boxColliders = car.GetComponentsInChildren <BoxCollider>();
                float         dlina        = 0;
                //Перебираем все боксы и оставляем самый большой размер, это будет длина
                for (int boxNum = 0; boxNum < boxColliders.Length; boxNum++)
                {
                    if (dlina < boxColliders[boxNum].size.x)
                    {
                        dlina = boxColliders[boxNum].size.x;
                    }
                    if (dlina < boxColliders[boxNum].size.y)
                    {
                        dlina = boxColliders[boxNum].size.y;
                    }
                    if (dlina < boxColliders[boxNum].size.z)
                    {
                        dlina = boxColliders[boxNum].size.z;
                    }
                }

                car.transform.position = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, gameObject.transform.position.z);
                CarStatic carStatic = car.GetComponent <CarStatic>();
                if (carStatic != null)
                {
                    car.transform.position += car.transform.forward * (dlina / 2 + carStatic.SpawnSdvig);
                }
            }
        }
    }