// If tagged as being explosive, then detonate, and disable gameobject. public void Die() { _breakingSound.pitch = (Random.Range(0.6f, 0.9f)); _breakingSound.Play(); Destroy(_fireObject); if (gameObject.tag == "explosiveObj") { _hasExploded = true; _explosive.Detonate(); } else { Instantiate(_woodExplosion, transform.position, transform.rotation, _PSObject.transform); gameObject.SetActive(false); } }
public void TriggerExplosion(string distance, string delay) { int intDistance; int.TryParse(distance, out intDistance); int intDelay; int.TryParse(delay, out intDelay); RaycastHit hit; if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit, intDistance, 1)) { Explosive explosive = hit.transform.GetComponent <Explosive>(); if (explosive != null) { StartCoroutine(explosive.Detonate(intDelay)); } } }