Example #1
0
        public void Initialize(GameObject newVehicle)
        {
            if (!newVehicle)
            {
                return;
            }
            targetVehicle = newVehicle;
            vp            = targetVehicle.GetComponent <VehicleParent>();

            trans = targetVehicle.GetComponentInChildren <Transmission>();
            if (trans)
            {
                if (trans is GearboxTransmission)
                {
                    gearbox = trans as GearboxTransmission;
                }
                else if (trans is ContinuousTransmission)
                {
                    varTrans = trans as ContinuousTransmission;
                }
            }

            if (stuntMode)
            {
                stunter = targetVehicle.GetComponent <StuntDetect>();
            }

            engine         = targetVehicle.GetComponentInChildren <Motor>();
            propertySetter = targetVehicle.GetComponent <PropertyToggleSetter>();

            stuntText.gameObject.SetActive(stuntMode);
            scoreText.gameObject.SetActive(stuntMode);
        }
        public void SpawnVehicle(int vehicle)
        {
            newVehicle = Instantiate(vehicles[vehicle], spawnPoint, Quaternion.LookRotation(spawnRot, GlobalControl.worldUpDir)) as GameObject;
            cam.target = newVehicle.transform;
            cam.Initialize();
            vp = newVehicle.GetComponent <VehicleParent>();

            trans = newVehicle.GetComponentInChildren <Transmission>();
            if (trans)
            {
                trans.automatic = autoShift;
                newVehicle.GetComponent <VehicleParent>().brakeIsReverse = autoShift;

                if (trans is GearboxTransmission)
                {
                    gearbox = trans as GearboxTransmission;
                }
                else if (trans is ContinuousTransmission)
                {
                    varTrans = trans as ContinuousTransmission;

                    if (!autoShift)
                    {
                        vp.brakeIsReverse = true;
                    }
                }
            }

            if (newVehicle.GetComponent <VehicleAssist>())
            {
                newVehicle.GetComponent <VehicleAssist>().enabled = assist;
            }

            if (newVehicle.GetComponent <FlipControl>() && newVehicle.GetComponent <StuntDetect>())
            {
                newVehicle.GetComponent <FlipControl>().flipPower          = stuntMode && assist ? new Vector3(10, 10, -10) : Vector3.zero;
                newVehicle.GetComponent <FlipControl>().rotationCorrection = stuntMode ? Vector3.zero : (assist ? new Vector3(5, 1, 10) : Vector3.zero);
                newVehicle.GetComponent <FlipControl>().stopFlip           = assist;
                stunter = newVehicle.GetComponent <StuntDetect>();
            }

            engine         = newVehicle.GetComponentInChildren <Motor>();
            propertySetter = newVehicle.GetComponent <PropertyToggleSetter>();

            stuntText.gameObject.SetActive(stuntMode);
            scoreText.gameObject.SetActive(stuntMode);
        }