// Update is called once per frame
 void Update()
 {
     Speed.text = "" + (int)(Target.GetComponent <Rigidbody>().velocity.magnitude * 3.6f);
     if ((Target.gear - 2) >= 0 && (Target.gear - 2) < GearImage.Length)
     {
         Gear.sprite = GearImage[Target.gear - 2];
     }
     RPM.fillAmount = Target.rpm / Target.maxRPM * 0.76f;
 }
Пример #2
0
	void Start(){
		myTransform=transform;
		
		trs = myTransform.parent;
		while (trs != null && trs.rigidbody == null) trs = trs.parent;
		if (trs != null) body = trs.rigidbody;
		
		trs = myTransform.parent;
		while (trs.GetComponent<PhysicMaterials>() == null)  {if (trs.parent) trs = trs.parent; else break;}
		physicMaterials = trs.GetComponent<PhysicMaterials>();

		trs = myTransform.parent;		
		while (trs.GetComponent<CarDynamics>() == null)  trs = trs.parent;
		cardynamics = trs.GetComponent<CarDynamics>();
		drivetrain = trs.GetComponent<Drivetrain>();
		axles = trs.GetComponent<Axles>();
    if (drivetrain != null)
      axisCarController = drivetrain.GetComponent<AxisCarController>();
		
		localScale=1/(trs.localScale.y*myTransform.localScale.y);
		
		layerMask=1<<trs.gameObject.layer | 1<<myTransform.gameObject.layer | 1 << 29 | 1 << 1 | 1 << 2;//LayerMask.NameToLayer("Wheel");
		layerMask=~layerMask;	
		
		radiusLoaded=radius;
		if (rimRadius==0) rimRadius=radius*0.735f;
		sidewallHeight=radius - rimRadius;

		if (mass<50*cardynamics.invFixedTimeStepScalar) mass=50*cardynamics.invFixedTimeStepScalar;
		if (rotationalInertia==0 || rotationalInertia<(mass/2)*radius*radius) rotationalInertia=(mass/2)*radius*radius;
		originalMass=mass;
				
		if (model==null) {
			model = new GameObject("temp_model");
			model.transform.parent=transform;
			model.transform.localPosition=new Vector3(0,0,0);
			model.transform.localRotation=Quaternion.identity;
			Debug.LogWarning("UnityCar: wheel model in " + wheelPos + " is missing. Using empty object" + " (" +trs.name+ ")");
		}
		
		modelTransform=model.transform;
		if (caliperModel!=null) caliperModelTransform=caliperModel.transform;
	
		skidmarks = cardynamics.skidmarks;
		//if (skidmarks) skidSmoke = skidmarks.GetComponentInChildren(typeof(ParticleEmitter)) as ParticleEmitter;//b
    if (skidmarks && enableSkidParticles)
    {
      skidSmoke = skidmarks.SmokePe;
      skidGrass = skidmarks.GrassPe;
      skidSand = skidmarks.SandPe;
      skidSnow = skidmarks.SnowPe;
    }
	  radiusTrack = radius;
	  radiusSnow = radius*0.6f;//b
		
		suspensionLineRenderer=gameObject.GetComponent<LineRenderer>();
		if (suspensionLineRenderer==null) suspensionLineRenderer = gameObject.AddComponent<LineRenderer>();
		suspensionLineRenderer.material = new Material(Shader.Find("Diffuse"));
		suspensionLineRenderer.material.color = Color.yellow;
		suspensionLineRenderer.SetWidth(0.01f,0.1f);
		suspensionLineRenderer.useWorldSpace = false;
		suspensionLineRenderer.castShadows = false;
	
		camber*=1; // to avoid never assigned warning
		if (camber==0){
			up = myTransform.up;
		}
		else{
			camberRotation = Quaternion.AngleAxis(-camber,forwardNormal);
			up = camberRotation*myTransform.up;
		}			
		
		SetTireStiffness();
	}