public void Hit(CamShakeMgr.Intensity shakeIntensity) { m_stunnedSomething = false; for (int i = 0; i < m_punchablesInRadius.Count; i++) { KeyValuePair <GameObject, IPunchable[]> target = m_punchablesInRadius[i]; if (target.Key == null) { m_punchablesInRadius.Remove(target); i--; } else if (!m_immuneTargets.Contains(target.Key)) { foreach (IPunchable punchableComponent in target.Value) { Vector3 hitVector = (target.Key.transform.position - transform.position).normalized * m_strength; punchableComponent.Punch(ModulateHitVector(hitVector), m_stunTime); if (target.Key.tag == "Player") { m_stunnedSomething = true; } } } } if (m_stunnedSomething) { CamShakeMgr.Get().Shake(shakeIntensity); } AfterHitting(); }
// Update is called once per frame private IEnumerator Explode(float delaySec) { yield return(new WaitForSeconds(delaySec)); if (!m_exploded) { m_exploded = true; Hit(ShakeIntensity); // Explosive items, unlike punch, should still shake the screen even if no one was hit if (!m_stunnedSomething) { CamShakeMgr.Get().Shake(ShakeIntensity); } audioSource.Play(); Rigidbody body = GetComponent <Rigidbody>(); body.constraints = RigidbodyConstraints.FreezeAll; Collider[] colliders = transform.GetComponentsInChildren <Collider>(); foreach (Collider collider in colliders) { collider.enabled = false; } Renderer[] meshes = transform.GetComponentsInChildren <Renderer>(); foreach (Renderer mesh in meshes) { mesh.enabled = false; } var blastwave = gameObject.GetComponentInChildren <Blastwave>(); blastwave.GetComponent <Renderer>().enabled = true; blastwave.Play(); var kaboom = gameObject.GetComponentInChildren <Kaboom>(); StartCoroutine(kaboom.Activate()); } }