Exemple #1
0
    private bool previousInvertMotorTorque;        //the value of inverMotorTorque from the previous update

    void Awake()
    {
        //get the wheel collider transforms
        wheels    = new Transform[4];
        wheels[0] = this.gameObject.GetChildObjectByName("FL_Collider").transform;
        wheels[1] = this.gameObject.GetChildObjectByName("FR_Collider").transform;
        wheels[2] = this.gameObject.GetChildObjectByName("BL_Collider").transform;
        wheels[3] = this.gameObject.GetChildObjectByName("BR_Collider").transform;
        //get the wheel model transforms
        wGraphics    = new Transform[4];
        wGraphics[0] = this.gameObject.GetChildObjectByName("FL_Tire").transform;
        wGraphics[1] = this.gameObject.GetChildObjectByName("FR_Tire").transform;
        wGraphics[2] = this.gameObject.GetChildObjectByName("BL_Tire").transform;
        wGraphics[3] = this.gameObject.GetChildObjectByName("BR_Tire").transform;
        //get the wheel colliders
        colls = new WheelCollider[4];
        for (int i = 0; i < 4; i++)
        {
            colls[i] = wheels[i].GetComponent <WheelCollider>();
        }
        //get a reference to the rigibody component component
        this.rigidBody = this.GetComponent <Rigidbody>();
        //set the center of mass of the vehicle
        this.rigidBody.centerOfMass = this.centerOfMass;
        //get a reference to the vehicle behaviour
        this.vehicleBehaviour = GetComponent <VehicleBehaviourBase>();
        //set the last known position of the vehicle
        this.lastPosition = this.transform.position;
        //set the start position of the vehicle
        this.startPosition = this.transform.position;
        //get a reference to the vehicle spotlight
        GameObject spotLight = this.gameObject.GetChildObjectByName("Vehicle Spotlight");

        //toggle the visibility of the vehicle spotlight
        if (this.vehicleSpotlight)
        {
            spotLight.GetComponent <Light> ().enabled = true;
        }
        else
        {
            spotLight.GetComponent <Light> ().enabled = false;
        }
    }
Exemple #2
0
    void Awake()
    {
        //get a reference to the primary vehicle in the scene
        if (this.targetVehicle == null)
        {
            this.targetVehicle = GameObject.FindGameObjectWithTag(TagManager.Vehicle).GetComponent <Vehicle> ();
        }
        this.vehicleBehaviour = this.targetVehicle.GetComponent <VehicleBehaviourBase> ();
        //get a list of all the child objects of this game object
        List <GameObject> li = new List <GameObject> ();

        this.gameObject.GetChildObjects(li);
        //get a reference to UI elements of
        foreach (GameObject go in li)
        {
            switch (go.name)
            {
            case "Heading":
                this.headingUI = go.GetComponent <InfoUIElement>();
                break;

            case "MotorTorque":
                this.motorTorqueUI = go.GetComponent <InfoUIElement>();
                break;

            case "Reversing":
                this.reversingUI = go.GetComponent <InfoUIElement>();
                break;

            case "Speed":
                this.speedUI = go.GetComponent <InfoUIElement>();
                break;

            case "FrontSteer":
                this.frontSteerUI = go.GetComponent <InfoUIElement>();
                break;

            case "RearSteer":
                this.rearSteerUI = go.GetComponent <InfoUIElement>();
                break;

            case "DragFactor":
                this.dragFactorUI = go.GetComponent <InfoUIElement>();
                break;

            case "LeftEye":
                this.leftEyeOutputUI = go.GetComponent <InfoUIElement>();
                break;

            case "RightEye":
                this.rightEyeOutputUI = go.GetComponent <InfoUIElement>();
                break;

            case "Distance":
                this.distanceUI = go.GetComponent <InfoUIElement>();
                break;

            case "Time":
                this.timeUI = go;
                break;
            }
        }
    }