Ejemplo n.º 1
0
        private void OnCollisionEnter(Collision hit)
        {
            if (!hit.gameObject ||
                hit.gameObject == weaponOwner.gameObject ||
                hit.gameObject == owner ||
                hit.gameObject.CompareTag("Perception") ||
                hit.gameObject.CompareTag("Projectile"))
            {
                return;
            }

            // Attempt to get a health component and apply some damage
            // #TODO: Use IDamageableInterface instead of requesting for component
            ITakeDamage otherHealth = hit.gameObject.GetComponent <ITakeDamage>();

            if (otherHealth != null)
            {
                otherHealth.OnTakeDamage(owner, damage, EDamageType.Fire);
            }

            if (DestroyOnImpact)
            {
                if (ExplosionPrefab)
                {
                    Vector3    hitLocation    = hit.contacts[0].point;
                    Quaternion hitOrientation = Quaternion.FromToRotation(Vector3.up, hit.contacts[0].normal);

                    GameObject particle = Instantiate(ExplosionPrefab, hitLocation, hitOrientation);

                    travelNoiseSource.Stop();

                    AudioSource explosionNoiseSource = particle.GetComponent <AudioSource>();
                    if (explosionNoiseSource && hitNoise)
                    {
                        explosionNoiseSource.PlayOneShot(hitNoise);
                    }
                }

                // Destroy ourselves
                gameObject.SetActive(false);
            }
        }
Ejemplo n.º 2
0
        protected void OnHit(Collider otherCollider)
        {
            // CJS - TODO: Find a more elegant way to ignore collisions with rooms
            if (otherCollider.gameObject == weaponOwner || otherCollider.gameObject.CompareTag("Weapon") || otherCollider.gameObject.CompareTag("Room"))
            {
                return;
            }

            Debug.Log(weaponOwner.name + " hit " + otherCollider.gameObject.name);

            // Do damage to our opponent
            ITakeDamage targetHealth = otherCollider.GetComponent <ITakeDamage>();

            if (targetHealth != null)
            {
                targetHealth.OnTakeDamage(weaponOwner, BaseProperties.DamageAmount, EDamageType.Slash);
            }

            // Interrupt our firing sound to play a contact hit sound
            BaseAudioProperties.FireNoiseSource.Stop();
            BaseAudioProperties.FireNoiseSource.clip = HitNoiseClip;
            BaseAudioProperties.FireNoiseSource.Play();
        }