private IEnumerator ExplodeRoutine() { yield return(new WaitForEndOfFrame()); Vector3 expPos = transform.position; var colliders = Physics.OverlapSphere(expPos, ExpRadius); foreach (var col in colliders) { var rigidbody = col.GetComponent <Rigidbody>(); if (rigidbody != null && rigidbody.GetInstanceID() != mId) { rigidbody.AddExplosionForce(ExpForce, expPos, ExpRadius, UpForce, ForceMode.Impulse); if (TagsAndLayers.IsShootable(rigidbody.tag)) { var mag = ExpRadius / ((rigidbody.transform.position - expPos).magnitude + 0.01f); rigidbody.GetComponent <Shootable>().Hit(mag * DamageFactor); } } } GameObject.Destroy(gameObject); }
protected override void Fire() { Vector2 randomScatter = Vector2.zero; if (DemoController.EnableScatteredSpray) { randomScatter = Random.insideUnitCircle * 0.02f; } if (DemoController.EnableShells) { FireEmptyShell(); } var ray = mMain.ViewportPointToRay(new Vector3(0.5f + randomScatter.x, 0.5f + randomScatter.y * mMain.aspect, 0f)); RaycastHit hitInfo; if (Physics.Raycast(ray, out hitInfo, MaxDistance, MaskLayer)) { if (DemoController.EnableBulletImpact) { CreateHitDecal(hitInfo); } //Debug.Log("Hit:" + hitInfo.transform.name); if (TagsAndLayers.IsShootable(hitInfo.collider.tag)) { var damage = Random.Range(MinDamage, MaxDamage); hitInfo.collider.gameObject.GetComponent <Shootable>().Hit(damage); } // Hit Kick Back if (DemoController.EnableHitKickBack) { // It affects everything which have rigidbody if (hitInfo.rigidbody != null) { hitInfo.rigidbody.AddForceAtPosition(-hitInfo.normal * 1.0f, hitInfo.point, ForceMode.Impulse); } } } }