Esempio n. 1
0
    protected virtual void OnPress(bool isPressed)
    {
        if (!isPressed)
        {
            truckCar.position = raceStart.CharPos.position;
            truckCar.rotation = raceStart.CharPos.rotation;

            baggageLabel.BaggageController = truckCar.GetComponentInChildren <BlowController>();

            GameObject t  = Instantiate(trailer, Vector3.zero, Quaternion.identity) as GameObject;
            Trailer    tr = t.GetComponentInChildren <Trailer>(); //Находим прицепа,
            if (tr != null)
            {
                tr.transform.position = truckCar.position;
                tr.transform.rotation = truckCar.rotation;
                truckCar.gameObject.AddComponent <CharacterJoint>();
                CharacterJoint characterJoint = truckCar.GetComponent <CharacterJoint>();
                characterJoint.connectedBody = tr.GetComponentInChildren <Rigidbody>();
                characterJoint.anchor        = connectPosition;
                SoftJointLimit softJointLimit = new SoftJointLimit();
                //softJointLimit.limit = 0;
                //characterJoint.lowTwistLimit = softJointLimit;
                softJointLimit.limit          = 25;
                characterJoint.highTwistLimit = softJointLimit; //вертикальный сустав
                softJointLimit.limit          = 105;
                characterJoint.swing1Limit    = softJointLimit; //горизонтальный сустав
                //softJointLimit.limit = 5;
                //truckCar.GetComponent<CharacterJoint>().swing2Limit = softJointLimit;//left/right
                truckCar.GetComponent <BlowController>().Frailty                    = tr.Frailty;//Передаем хрупкость на тягач
                truckCar.GetComponent <BlowController>().Condition                  = 100;
                truckCar.GetComponent <AxisCarController>().Trailer                 = tr.GetComponentInChildren <Rigidbody>();
                truckCar.GetComponent <AxisCarController>().SignalTrailerLeft       = tr.SignalLeft;
                truckCar.GetComponent <AxisCarController>().SignalTrailerRight      = tr.SignalRight;
                truckCar.GetComponentInChildren <BlowController>().TrailerTransform = tr.GetComponentInChildren <Rigidbody>().transform;
                truckCar.GetComponentInChildren <BlowController>().Box              = tr.Box;
            }
            Array.Resize(ref enemies, raceStart.enemiesPos.Length);
            int i = 0;
            foreach (var e in raceStart.enemiesPos)//Создаем соперников
            {
                GameObject enemyTractor = Instantiate(raceStart.enemiesPos[i].EnemyPref, e.EnemyPos.position, e.EnemyPos.rotation) as GameObject;
                if (enemyTractor != null)
                {
                    raceStart.mapScroll.Enemies[i] = enemyTractor.transform;//b
                    enemyTractor.GetComponentInChildren <AxisCarController>().SetWay(way);
                    enemies[i] = enemyTractor;
                    GameObject ts = Instantiate(trailer, Vector3.zero, Quaternion.identity) as GameObject;
                    //Destroy(ts.GetComponentInChildren<Skidmarks>().gameObject);//Удалить следы у соперников
                    Trailer trs = ts.GetComponentInChildren <Trailer>(); //Находим прицепа soprnika,
                    if (trs != null)
                    {
                        trs.transform.position = enemyTractor.transform.position;
                        trs.transform.rotation = enemyTractor.transform.rotation;
                        enemyTractor.GetComponent <CharacterJoint>().connectedBody              = trs.GetComponentInChildren <Rigidbody>();
                        enemyTractor.GetComponent <AxisCarController>().Trailer                 = trs.GetComponentInChildren <Rigidbody>();
                        enemyTractor.GetComponent <AxisCarController>().SignalTrailerLeft       = trs.GetComponent <Trailer>().SignalLeft;
                        enemyTractor.GetComponent <AxisCarController>().SignalTrailerRight      = trs.GetComponent <Trailer>().SignalRight;
                        enemyTractor.GetComponentInChildren <RenderContainer>().trailer         = trs.GetComponentInChildren <Rigidbody>();
                        enemyTractor.GetComponentInChildren <BlowController>().TrailerTransform = trs.GetComponentInChildren <Rigidbody>().transform;
                        enemyTractor.GetComponentInChildren <BlowController>().Box              = trs.Box;
                        enemyTractor.GetComponent <BlowController>().Frailty   = trs.Frailty;//Передаем хрупкость на тягач
                        enemyTractor.GetComponent <BlowController>().Condition = 100;
                    }
                    i += 1;
                }
                else
                {
                    Debug.LogWarning("opp == null");
                }
            }
            raceFinish.Activ = true;
            raceStart.ExitStation();
            raceStart.ClockOn();
            raceFinish.Price            = price;
            raceFinish.buttonAddTrailer = this;
            buttonThrottle.NitroFuel    = 100;
            //
            CarZona[] carZones = FindObjectsOfType <CarZona>();
            foreach (var carZone in carZones)
            {
                carZone.Enemies = enemies;
            }
            //Создание бонусов
            baggageLabel.bonusPosCtrl.CreateBonuses(cargoId);
            raceStart.MapCamera.SetActive(true);
        }
    }