IEnumerator ChainReact(int chainDepth) { Collider[] allNear = Physics.OverlapSphere(transform.position, blastRadius); for (int i = 0; i < allNear.Length; i++) { ExplodeChainReact ecrScript = allNear[i].gameObject.GetComponent <ExplodeChainReact>(); if (ecrScript && gameObject != allNear[i].gameObject) // can explode, and isn't self { Debug.Log("CHAIN (" + chainDepth + ") from " + gameObject.name + " to " + allNear[i].gameObject.name); ecrScript.Explode(chainDepth + 1); } } yield return(new WaitForSeconds(chainDepth * Random.Range(0.1f, 0.4f))); // lag the explosion GameObject pointGO = GameObject.Instantiate(pointPopper, transform.position, transform.rotation); PointScaleFadeDie psfdScript = pointGO.GetComponent <PointScaleFadeDie>(); psfdScript.SetText(chainDepth + "00", chainDepth); ScoreKeeper.instance.AddScore(100 * chainDepth); GameObject.Instantiate(blastVFX, transform.position, transform.rotation); Destroy(gameObject); }
IEnumerator ChainReact(int chainDepth) { Collider[] allNear = Physics.OverlapSphere(transform.position, blastRadius); for (int i = 0; i < allNear.Length; i++) { ExplodeChainReact ecrScript = allNear[i].gameObject.GetComponentInParent <ExplodeChainReact>(); if (ecrScript && gameObject != allNear[i].gameObject) // can explode, and isn't self { Debug.Log("CHAIN (" + chainDepth + ") from " + gameObject.name + " to " + allNear[i].gameObject.name); ecrScript.Explode(chainDepth + 1); } } yield return(new WaitForSeconds(chainDepth * Random.Range(0.1f, 0.4f))); // lag the explosion Destroy(gameObject); GameObject pointGO = GameObject.Instantiate(pointPopper, transform.position, transform.rotation); PointScaleFadeDie psfdScript = pointGO.GetComponent <PointScaleFadeDie>(); int score = chainDepth * 100; psfdScript.SetText(score, chainDepth); ScoreKeeper.instance.AddScore(score); // UI Elements Handling if (TotalNumberOfTargetHits && ScoreList) { TotalNumberOfTargetHits.value += 1; if (chainDepth == 1) { ScoreList.value.Add(score); NumberOfTargetsList.value.Add(chainDepth); } else if (chainDepth > 1) { int index; index = ScoreList.value.Count - 1; if (index >= 0 && index < ScoreList.value.Count) { ScoreList.value[ScoreList.value.Count - 1] += score; } else { Debug.LogWarning("INVALID INDEX attempt blocked"); } index = NumberOfTargetsList.value.Count - 1; if (index >= 0 && index < NumberOfTargetsList.value.Count) { NumberOfTargetsList.value[NumberOfTargetsList.value.Count - 1] += 1; } else { Debug.LogWarning("INVALID INDEX attempt blocked"); } } } else { Debug.LogWarning("NOTE: TotalNumberOfTargetHits AND/OR ScoreList isn't set in this scene"); } }