private void Start() { _currentTerrainFeature = GameObject.Find("Track").GetComponent <ITerrainFeature>(); _wheelTransform = GetComponentInChildren <MeshRenderer>().transform; _skidSound = GetComponent <AudioSource>(); _trailParticleEffectBehaviour = trailParticleEffect.GetComponent <TrailParticleEffect>(); }
private void SetTerrain(WheelHit hit) { ITerrainFeature terrainHit = hit.collider.GetComponent <ITerrainFeature>(); if (!terrainHit.Equals(_currentTerrainFeature)) { // Debug.Log("Terrain Feature: "+terrainHit.name); // Debug.Log("Previous Feature: "+_currentTerrainFeature.name); ParticleSystem newTrailParticleEffect = Instantiate(terrainHit.GetTrailParticleEffect(), trailParticleEffect.transform.parent, false); newTrailParticleEffect.transform.position = trailParticleEffect.transform.position; _trailParticleEffectBehaviour.ScheduleDestroy(); trailParticleEffect = newTrailParticleEffect; _trailParticleEffectBehaviour = trailParticleEffect.GetComponent <TrailParticleEffect>(); _skidSound.Stop(); _skidSound.clip = terrainHit.GetTrailAudioClip(); TrailRenderer newTrail = Instantiate(trailEffect, trailEffect.transform.parent, false).GetComponent <TrailRenderer>(); newTrail.material = terrainHit.GetTrailMaterial(); newTrail.transform.position = trailEffect.transform.position; trailEffect.autodestruct = true; trailEffect.emitting = false; trailEffect = newTrail; _currentTerrainFeature = terrainHit; } }