public void Delete() { if (OnDelete != null) { OnDelete.Invoke(VehicleBehaviour); } Destroy(gameObject); }
private void GenerateVehicle(VehicleBehaviour prefab, Vehicle vehicle) { var behaviour = Instantiate(prefab); behaviour.Vehicle = vehicle; if (onVehicleGenerated != null) { onVehicleGenerated.Invoke(behaviour); } }
IEnumerator Explode() { destroying = true; bodyMesh.gameObject.SetActive(false); explosionParticles.Play(); yield return(new WaitUntil(() => explosionParticles.isStopped)); OnDestroyed.Invoke(this); Destroy(gameObject); }
private IEnumerator LoopCoroutine() { while (true) { if (vehicleBehaviours.Any(x => x.DistanceFromStart < racetrackBehaviour.Racetrack.Length)) { foreach (var behaviour in vehicleBehaviours.Where(x => x.DistanceFromStart < racetrackBehaviour.Racetrack.Length)) { if (behaviour.BlowoutTimer > 0) { behaviour.BlowoutTimer -= refreshRate; } else { if (Random.Range(0, 100) <= behaviour.Vehicle.TireBlowoutChance) { behaviour.BlowoutTimer += blowoutTimeout; if (onTireBlowout != null) { onTireBlowout.Invoke(behaviour); } } else { behaviour.DistanceFromStart += behaviour.Vehicle.GetSpeed(); racetrackBehaviour.SetToWorldPosition(behaviour.DistanceFromStart, behaviour.transform); if (behaviour.DistanceFromStart >= racetrackBehaviour.Racetrack.Length) { behaviour.Place = lastPlace; lastPlace++; } } } } } else { EndLoop(); yield break; } yield return(new WaitForSeconds(refreshRate)); } }