public void SetWheels()
    {
        if (frontAxle.leftWheel)
        {
            frontAxle.leftWheel.wheelPos = WheelPos.FRONT_LEFT;
        }
        if (frontAxle.rightWheel)
        {
            frontAxle.rightWheel.wheelPos = WheelPos.FRONT_RIGHT;
        }
        if (rearAxle.leftWheel)
        {
            rearAxle.leftWheel.wheelPos = WheelPos.REAR_LEFT;
        }
        if (rearAxle.rightWheel)
        {
            rearAxle.rightWheel.wheelPos = WheelPos.REAR_RIGHT;
        }

        frontAxle.wheels = new Wheel[0];
        if (frontAxle.leftWheel != null && frontAxle.rightWheel != null)
        {
            frontAxle.wheels    = new Wheel[2];
            frontAxle.wheels[0] = frontAxle.leftWheel;
            frontAxle.wheels[1] = frontAxle.rightWheel;
        }
        else if (frontAxle.leftWheel != null || frontAxle.rightWheel != null)
        {
            frontAxle.wheels = new Wheel[1];
            if (frontAxle.leftWheel != null)
            {
                frontAxle.wheels[0] = frontAxle.leftWheel;
            }
            else
            {
                frontAxle.wheels[0] = frontAxle.rightWheel;
            }
        }
        frontAxle.camber = Mathf.Clamp(frontAxle.camber, -10, 10);

        rearAxle.wheels = new Wheel[0];
        if (rearAxle.leftWheel != null && rearAxle.rightWheel != null)
        {
            rearAxle.wheels    = new Wheel[2];
            rearAxle.wheels[0] = rearAxle.leftWheel;
            rearAxle.wheels[1] = rearAxle.rightWheel;
        }
        else if (rearAxle.leftWheel != null || rearAxle.rightWheel != null)
        {
            rearAxle.wheels = new Wheel[1];
            if (rearAxle.leftWheel != null)
            {
                rearAxle.wheels[0] = rearAxle.leftWheel;
            }
            else
            {
                rearAxle.wheels[0] = rearAxle.rightWheel;
            }
        }
        rearAxle.camber = Mathf.Clamp(rearAxle.camber, -10, 10);

        Wheel[] m_otherWheels = new Wheel[otherAxles.Length * 2];
        int     i             = 0;

        foreach (Axle axle in otherAxles)
        {
            if (axle.leftWheel != null && axle.rightWheel != null)
            {
                axle.wheels    = new Wheel[2];
                axle.wheels[0] = m_otherWheels[i] = axle.leftWheel;
                axle.wheels[1] = m_otherWheels[i + 1] = axle.rightWheel;
                i += 2;
            }
            else
            {
                axle.wheels = new Wheel[1];
                if (axle.leftWheel != null)
                {
                    axle.wheels[0] = m_otherWheels[0] = axle.leftWheel;
                }
                else
                {
                    axle.wheels[0] = m_otherWheels[0] = axle.rightWheel;
                }
                i += 1;
            }
            axle.camber = Mathf.Clamp(axle.camber, -10, 10);
        }

        otherWheels = new Wheel[i];
        m_otherWheels.CopyTo(otherWheels, 0);

        allWheels = new Wheel[frontAxle.wheels.Length + rearAxle.wheels.Length + otherWheels.Length];

        frontAxle.wheels.CopyTo(allWheels, 0);
        rearAxle.wheels.CopyTo(allWheels, frontAxle.wheels.Length);
        if (otherWheels.Length != 0)
        {
            otherWheels.CopyTo(allWheels, frontAxle.wheels.Length + rearAxle.wheels.Length);
        }
    }
示例#2
0
	public void SetWheels(){
		if (frontAxle.leftWheel) frontAxle.leftWheel.wheelPos=WheelPos.FRONT_LEFT;		
		if (frontAxle.rightWheel) frontAxle.rightWheel.wheelPos=WheelPos.FRONT_RIGHT;
		if (rearAxle.leftWheel) rearAxle.leftWheel.wheelPos=WheelPos.REAR_LEFT;
		if (rearAxle.rightWheel) rearAxle.rightWheel.wheelPos=WheelPos.REAR_RIGHT;
		
		frontAxle.wheels =new Wheel[0];
		if (frontAxle.leftWheel!=null && frontAxle.rightWheel!=null) {
			frontAxle.wheels =new Wheel[2];
			frontAxle.wheels[0]=frontAxle.leftWheel;
			frontAxle.wheels[1]=frontAxle.rightWheel;
		}
		else if (frontAxle.leftWheel!=null || frontAxle.rightWheel!=null){
			frontAxle.wheels =new Wheel[1];
			if (frontAxle.leftWheel!=null) frontAxle.wheels[0]=frontAxle.leftWheel;
			else frontAxle.wheels[0]=frontAxle.rightWheel;
		}
		frontAxle.camber=Mathf.Clamp(frontAxle.camber,-10,10);
		
		rearAxle.wheels =new Wheel[0];
		if (rearAxle.leftWheel!=null && rearAxle.rightWheel!=null) {
			rearAxle.wheels =new Wheel[2];
			rearAxle.wheels[0]=rearAxle.leftWheel;
			rearAxle.wheels[1]=rearAxle.rightWheel;
		}
		else if (rearAxle.leftWheel!=null || rearAxle.rightWheel!=null) {
			rearAxle.wheels =new Wheel[1];
			if (rearAxle.leftWheel!=null) rearAxle.wheels[0]=rearAxle.leftWheel;
			else rearAxle.wheels[0]=rearAxle.rightWheel;
		}
		rearAxle.camber=Mathf.Clamp(rearAxle.camber,-10,10);
		
		Wheel[] m_otherWheels=new Wheel[otherAxles.Length*2];
		int i=0;
		foreach(Axle axle in otherAxles){
			if (axle.leftWheel!=null && axle.rightWheel!=null) {
				axle.wheels =new Wheel[2];
				axle.wheels[0]=m_otherWheels[i]=axle.leftWheel;
				axle.wheels[1]=m_otherWheels[i+1]=axle.rightWheel;
				i+=2;
			}
			else{
				axle.wheels =new Wheel[1];
				if (axle.leftWheel!=null) axle.wheels[0]=m_otherWheels[0]=axle.leftWheel;
				else axle.wheels[0]=m_otherWheels[0]=axle.rightWheel;
				i+=1;
			}
			axle.camber=Mathf.Clamp(axle.camber,-10,10);
		}		
		
		otherWheels=new Wheel[i];
		m_otherWheels.CopyTo(otherWheels, 0);
		
		allWheels = new Wheel[frontAxle.wheels.Length + rearAxle.wheels.Length + otherWheels.Length];
		
		frontAxle.wheels.CopyTo(allWheels, 0);
		rearAxle.wheels.CopyTo(allWheels, frontAxle.wheels.Length);
		if (otherWheels.Length!=0) otherWheels.CopyTo(allWheels,frontAxle.wheels.Length + rearAxle.wheels.Length);
	}