private void HitSomething(RaycastHit hitInfo, WeaponMount weaponMount) { if (weaponMount.Weapon.Projectile != null) { InstantiateProjectile(weaponMount, (hitInfo.point - weaponMount.FirePosition.position).normalized); } else { Health health = hitInfo.transform.GetComponent <Health>(); if (health != null) { health.TakeDamage(weaponMount.Weapon.Damage, _player.gameObject, weaponMount.Weapon.DamageParticleType); } else { GlassBreaker glassBreaker = hitInfo.transform.GetComponent <GlassBreaker>(); if (glassBreaker != null) { glassBreaker.BreakerGlass(); } else { Rigidbody rigidbody = hitInfo.transform.GetComponent <Rigidbody>(); if (rigidbody != null) { rigidbody.AddForce(_player.transform.forward * weaponMount.Weapon.PushForce); } else { GameObject tmp = Instantiate(weaponMount.Weapon.BulletHole, hitInfo.point + hitInfo.normal * .01f, Quaternion.identity); tmp.transform.forward = -hitInfo.normal; tmp.transform.parent = hitInfo.transform; } } } } }
private void Hit(GameObject other) { if (_rigidBody.velocity.magnitude < _minDamageVelocity) { return; } if (_didHit) { return; } // We don't hit ourselves if (other == _attacker) { return; } _didHit = true; GlassBreaker glassBreaker = other.transform.GetComponent <GlassBreaker>(); if (glassBreaker != null) { glassBreaker.BreakerGlass(); } Health health = other.transform.GetComponent <Health>(); if (health != null) { health.TakeDamage(_damage, _attacker, _damageParticleType); } if (_hitEffect != null) { Instantiate(_hitEffect, _hitEffectSpawnPositionTransform.position, Quaternion.identity); } switch (_hitBehavior) { case OnHitBehavior.Destroy: Destroy(gameObject); break; case OnHitBehavior.GetStuck: if (health == null) { _rigidBody.isKinematic = true; GetComponent <Collider>().enabled = false; } transform.parent = other.transform; TrailRenderer trailRenderer = GetComponent <TrailRenderer>(); if (trailRenderer != null) { trailRenderer.enabled = false; } break; default: break; } }