public void FireRandom() { if (transform.childCount == 0) { return; } int ignited = 0; for (int i = 0; i < randomIgnition; i++) { Combustible combustible; foreach (Transform child in transform) { if (ignited >= randomIgnition) { return; } if ((combustible = child.GetComponent <Combustible>()) == null) { continue; } if (!combustible.IsHealthy()) { continue; } weatherControl.IgniteFire(combustible.transform.position); ignited++; } } }
// Simple interaction method to determine user input from mouse // Based on InteractionMode enum set through the user panel it process the input private void ProcessInteraction() { if (Input.GetKeyDown(controlsConfig.lbm)) { RaycastHit hit; if (Physics.Raycast(GetMouseRay(), out hit, interactionLayerMask)) { switch (interactionMode) { // Adding plants case InteractionMode.Add: if (hit.transform.GetComponent <Combustible>() == null) { vegetationFactory.SpawnFlower(hit.point); } break; // Removing plants case InteractionMode.Remove: Flower flower = hit.transform.GetComponent <Flower>(); if (flower != null) { vegetationFactory.RemoveFlower(flower); } break; // Toggle between ignition and extinguishing case InteractionMode.Toggle: Combustible combustible = hit.transform.GetComponent <Combustible>(); if (combustible == null) { return; } if (combustible.IsBurning()) { combustible.Extinguish(); } else { weatherControl.IgniteFire(hit.point); } break; } } } ; }