public void OnDeath(HitContext hitContext)
        {
            _pushback = hitContext.Direction / 20.0f;

            if (_isDead) return;

            if (!hitContext.IsMelee) {
                var ejector = gameObject.GetComponent<BloodEjector>();
                if (ejector != null)
                {
                    ejector.Eject(hitContext);
                    ejector.Eject(hitContext);
                    ejector.Eject(hitContext);
                }
            }

            Destroy(GetComponent<EnemyMovement>());
            Destroy(GetComponent<NavMeshAgent>());

            _isDead = true;
            GetComponent<Animator>().SetBool("IsDead", true);
            GetComponent<Animator>().SetBool("IsAttacking", false);
            gameObject.layer = LayerMask.NameToLayer("TurnStaticSoon");
            GetComponent<EnemySounds>().PlayDeathSound();

            GetComponent<Rigidbody>().isKinematic = false;
            GetComponent<Rigidbody>().AddExplosionForce(hitContext.Force / 2.0f, transform.position - hitContext.Direction, 1f, .5f, ForceMode.Impulse);
            
            EventAggregator.SendMessage(new EnemyKilledMessage());
        }
        public void TakeDamage(HitContext context)
        {
            Health -= context.Damage;

            if (Health <= 0)
            {
                Health = 0;
                _damageBehavior.OnDeath(context);
            }
            else
            {
                _damageBehavior.OnHit(context);
            }
        }
Exemple #3
0
        public void TakeDamage(HitContext context)
        {
            Health -= context.Damage;

            if (Health <= 0)
            {
                Health = 0;
                _damageBehavior.OnDeath(context);
            }
            else
            {
                _damageBehavior.OnHit(context);
            }
        }
        void OnTriggerEnter(Collider col)
        {
            var bullet = col.GetComponent<Bullet>();

            if (bullet != null && ShouldCollideWith(bullet))
            {
                var hitContext = new HitContext {
                    Direction = bullet.transform.forward, 
                    Force = bullet.Speed, 
                    Damage = bullet.Damage, 
                    IsMelee = false
                };
                TakeDamage(hitContext);
            }
        }
Exemple #5
0
        void OnTriggerEnter(Collider col)
        {
            var bullet = col.GetComponent <Bullet>();

            if (bullet != null && ShouldCollideWith(bullet))
            {
                var hitContext = new HitContext {
                    Direction = bullet.transform.forward,
                    Force     = bullet.Speed,
                    Damage    = bullet.Damage,
                    IsMelee   = false
                };
                TakeDamage(hitContext);
            }
        }
 public void Attack()
 {
     if (Vector3.Distance(transform.position, _player.transform.position) < MinDistance)
     {
         GetComponent<EnemySounds>().PlayAttackSound();            
         var hitContext = new HitContext
         {
             Force = 3,
             Damage = Damage,
             Direction = transform.forward,
             IsMelee = true
         };
         _player.GetComponent<HealthBehavior>().TakeDamage(hitContext);
     }
 }
        public void OnHit(HitContext hitContext)
        {
            if (_isDead) return;

            _pushback = hitContext.Direction / 20.0f;

            GetComponent<Animator>().SetTrigger("IsHit");
            GetComponent<EnemySounds>().PlayHitSound();

            if (!hitContext.IsMelee) {
                var ejector = gameObject.GetComponent<BloodEjector>();
                if (ejector != null)
                {
                    ejector.Eject(hitContext);
                }
            }
        }
        public void OnDeath(HitContext hitContext)
        {
            var rigidBody = GetComponent<Rigidbody>();
            rigidBody.constraints = RigidbodyConstraints.None;
            rigidBody.AddExplosionForce(hitContext.Force * 2, transform.position - hitContext.Direction, 1f, 3f, ForceMode.Impulse);

            gameObject.GetComponent<BoxCollider>().center = Vector3.zero;
            gameObject.GetComponent<BoxCollider>().size = new Vector3(.4f,.3f, .27f);

            Destroy(GetComponent<CapsuleCollider>());
            Destroy(GetComponentInChildren<MouseRotationX>());
            Destroy(GetComponentInChildren<MouseRotationY>());
            Destroy(GetComponentInChildren<KeyboardMovement>());
            Destroy(GetComponentInChildren<Bobber>());
            Destroy(GetComponentInChildren<Tilter>());
            Destroy(GetComponentInChildren<PlayerInteractions>());
            Destroy(gameObject.GetComponent<PlayerGun>());
            Destroy(Hand);
        }
        public void Eject(HitContext hitContext)
        {
            // initial burst
            for (var i = 0; i < 10; i++)
            {
                var blood = Instantiate(BloodDroplet);
                blood.transform.position = transform.position + new Vector3(0, .2f, 0);
                blood.GetComponent<Rigidbody>().AddForce(Random.onUnitSphere.PositiveY() * Random.Range(MinForce, MaxForce));
            }

            // follow bullet path
            for (var i = 0; i < 10; i++)
            {
                var blood = Instantiate(BloodDroplet);
                blood.transform.position = transform.position + new Vector3(0, .2f, 0);
                var path = hitContext.Direction*Random.Range(MinForce, MaxForce)*hitContext.Force;
                path.y = Random.Range(0f, 250f);
                blood.GetComponent<Rigidbody>().AddForce(path);
            }
        }
Exemple #10
0
        public void MeleeAttack()
        {
            _lastShot = Time.fixedTime;

            var ray = _viewCamera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit) && Vector3.Distance(transform.position, hit.point) < .5f)
            {
                if (hit.collider.tag == "Enemy")
                {
                    var hitContext = new HitContext
                    {
                        Damage = Random.Range(0, 2),
                        Direction = transform.forward,
                        Force = 1,
                        IsMelee = true                    
                    };
                    hit.collider.GetComponent<HealthBehavior>().TakeDamage(hitContext);
                }
            }
        }
 public void OnHit(HitContext hitContext)
 {
     // TODO: Flash screen red or some shit here
 }