/// <summary> /// Reinit this vehicle. Reset to default state. /// Should be called when player restarts /// </summary> /// <param name="accelerate">true, if start speed of this vehicle must be 0</param> public void Reinit(bool accelerate) { playerRigidbody.isKinematic = true; // default values currentSpeed = accelerate ? 0 : DefaultSpeed; currentSideSpeed = accelerate ? 0 : DefaultSideSpeed; targetSpeed = currentSpeed; targetSideSpeed = currentSideSpeed; TravelledDistance = 0; OnDistanceChange?.Invoke(TravelledDistance); Health = MaxHealth; OnVehicleHealthChange?.Invoke(Health); // stop and remove existing particles engineSmoke.Stop(); engineFire.Stop(); engineSmoke.Clear(true); engineFire.Clear(true); SteeringWheel.Restart(); OnVehicleStart?.Invoke(); }
public void ReceiveDamage(Damage damage) { if (Health == 0) { return; } Health -= damage.CalculateDamageValue(playerTransform.position); // play damage particle system hitParticles.transform.position = damage.Type == DamageType.Bullet ? damage.Point : transform.position; hitParticles.transform.rotation = Quaternion.LookRotation( damage.Type == DamageType.Bullet ? damage.Normal : damage.Point - transform.position); hitParticles.Play(); if (Health <= SmokeHealthPercentage * MaxHealth) { engineSmoke.Play(); } if (Health <= FireHealthPercentage * MaxHealth) { engineFire.Play(); } if (Health <= 0) { Health = 0; // stop vehicle Brake(); // explode StartCoroutine(WaitToExplode(TimeToExplode)); } OnVehicleHealthChange?.Invoke(Health); }