void Start() { //soundVolume = GameObject.Find("SoundVolume").GetComponent<UISlider>(); selectCarController = GameObject.Find("Controller").GetComponent <SelectCarController>(); carController = GetComponent <CarController>(); cardynamics = GetComponent <CarDynamics>(); drivetrain = GetComponent <Drivetrain>(); physicMaterials = GetComponent <PhysicMaterials>(); axles = GetComponent <Axles>(); Vector3 enginePositionV = Vector3.zero; if (enginePosition != null) { enginePositionV = enginePosition.transform.position; } engineThrottleSource = CreateAudioSource(engineThrottle, true, true, enginePositionV); engineNoThrottleSource = CreateAudioSource(engineNoThrottle, true, true, enginePositionV); transmissionSource = CreateAudioSource(transmission, true, true, Vector3.zero); brakeNoiseSource = CreateAudioSource(brakeNoise, true, true, Vector3.zero); startEngineSource = CreateAudioSource(startEngine, true, false, enginePositionV); startEngineSource.volume = startEngineVolume * selectCarController.VolumeEffects;//b startEngineSource.pitch = startEnginePitch; System.Array.Resize(ref skidSource, axles.allWheels.Length); i = 0; foreach (Wheel w in axles.allWheels) { skidSource[i] = CreateAudioSource(skid, true, true, w.transform.localPosition); i++; } crashHiSpeedSource = CreateAudioSource(crashHiSpeed, false, false, Vector3.zero); crashLowSpeedSource = CreateAudioSource(crashLowSpeed, false, false, Vector3.zero); scrapeNoiseSource = CreateAudioSource(scrapeNoise, false, false, Vector3.zero); ABSTriggerSource = CreateAudioSource(ABSTrigger, false, false, Vector3.zero); ABSTriggerSource.volume = ABSTriggerVolume; shiftTriggerSource = CreateAudioSource(shiftTrigger, false, false, Vector3.zero); shiftTriggerSource.volume = shiftTriggerVolume; windSource = CreateAudioSource(wind, true, true, Vector3.zero); if (physicMaterials) { System.Array.Resize(ref rollingNoiseSource, axles.allWheels.Length); i = 0; foreach (Wheel w in axles.allWheels) { rollingNoiseSource[i] = CreateAudioSource(rollingNoiseGrass, true, false, w.transform.localPosition); i++; } } }
void SetComponent(){ drivetrain = GetComponent<Drivetrain>(); cardynamics = GetComponent<CarDynamics>(); forceFeedback= GetComponent<ForceFeedback>(); physicMaterials =GetComponent<PhysicMaterials>(); arcader= GetComponent<Arcader>(); aerodynamicResistance= GetComponent<AerodynamicResistance>(); axles= GetComponent<Axles>(); axisCarController = GetComponent <AxisCarController>(); mouseCarController = GetComponent <MouseCarController>(); mobileCarController = GetComponent <MobileCarController>(); fuelTanks=GetComponentsInChildren<FuelTank>(); wings=GetComponentsInChildren<Wing>(); }
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>(); localScale=1/(trs.localScale.y*myTransform.localScale.y); layerMask=1<<trs.gameObject.layer | 1<<myTransform.gameObject.layer;//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; 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(); }
void Start () { carController = GetComponent<CarController>(); cardynamics = GetComponent<CarDynamics>(); drivetrain= GetComponent<Drivetrain>(); physicMaterials =GetComponent<PhysicMaterials>(); axles=GetComponent<Axles>(); Vector3 enginePositionV=Vector3.zero; if (enginePosition!=null) enginePositionV=enginePosition.transform.position; engineThrottleSource = CreateAudioSource(engineThrottle, true, true,enginePositionV); engineNoThrottleSource = CreateAudioSource(engineNoThrottle, true, true,enginePositionV); transmissionSource = CreateAudioSource(transmission, true, true,Vector3.zero); brakeNoiseSource = CreateAudioSource(brakeNoise, true, true,Vector3.zero); startEngineSource= CreateAudioSource(startEngine, true, false,enginePositionV); startEngineSource.volume=startEngineVolume; startEngineSource.pitch=startEnginePitch; System.Array.Resize(ref skidSource,axles.allWheels.Length); i=0; foreach(Wheel w in axles.allWheels){ skidSource[i] = CreateAudioSource(skid, true, true,w.transform.localPosition); i++; } crashHiSpeedSource = CreateAudioSource(crashHiSpeed, false, false,Vector3.zero); crashLowSpeedSource = CreateAudioSource(crashLowSpeed, false, false,Vector3.zero); scrapeNoiseSource = CreateAudioSource(scrapeNoise, false, false,Vector3.zero); ABSTriggerSource= CreateAudioSource(ABSTrigger, false, false,Vector3.zero); ABSTriggerSource.volume=ABSTriggerVolume; shiftTriggerSource= CreateAudioSource(shiftTrigger, false, false,Vector3.zero); shiftTriggerSource.volume=shiftTriggerVolume; windSource = CreateAudioSource(wind, true, true,Vector3.zero); if (physicMaterials){ System.Array.Resize(ref rollingNoiseSource,axles.allWheels.Length); i=0; foreach(Wheel w in axles.allWheels){ rollingNoiseSource[i]=CreateAudioSource(rollingNoiseGrass, true, false,w.transform.localPosition); i++; } } }
void Start() { myTransform = transform; trs = myTransform.parent; //while (trs != null && trs.rigidbody == null) trs = trs.parent; //if (trs != null) body = trs.rigidbody; //Rigidbody rb = trs.GetComponent<Rigidbody>(); //while (trs != null && trs.gameObject.GetComponent<Rigidbody>() == null) trs = trs.parent; //if (trs != null) body = trs.gameObject.GetComponent<Rigidbody>(); if (body == null) { Rigidbody rb; do { rb = trs.GetComponent <Rigidbody>(); trs = trs.parent; }while (trs != null && rb == null); if (trs != null) { body = rb; } } //if (!trs.TryGetComponent<Rigidbody>(out body)) trs = trs.parent; 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>(); localScale = 1 / (trs.localScale.y * myTransform.localScale.y); layerMask = 1 << trs.gameObject.layer | 1 << myTransform.gameObject.layer; //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; //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(); }