void OnCollisionEnter(Collision collision)
 {
     if (state == TentacleState.grabbing)
     {
         if (collision.gameObject.tag == "Moveable" || collision.gameObject.tag == "Enemy")
         {
             holding = collision.gameObject;
             Rigidbody rigBod = holding.GetComponent <Rigidbody>();
             rigBod.isKinematic = true;
             holding.layer      = 9;
             state = TentacleState.holding;
         }
         if (holding.tag == "Enemy")
         {
             ParentEnemy enemy = holding.GetComponent <ParentEnemy>();
             enemy.isGrabbed = true;
         }
     }
     if (state == TentacleState.holding)
     {
         if (collision.gameObject.tag == "Wall")
         {
             inWall = true;
         }
     }
 }
Exemple #2
0
        public override void TakeDamage(double damage)
        {
            ParentEnemy?.TakeDamage(damage);

            LifePoints = LifePoints - damage;
            if (LifePoints <= 0)
            {
                Alive = false;
            }
        }
 void OnCollisionEnter(Collision collision)
 {
     if (collision.gameObject.tag == "Enemy")
     {
         if (_canTakeDamage)
         {
             ParentEnemy enemy = collision.gameObject.GetComponent <ParentEnemy>();
             if (enemy.isGrabbed == false)
             {
                 HitPoints--;
                 if (HitPoints < 0)
                 {
                     _canMove     = false;
                     _canAim      = false;
                     respawnDelay = Time.time + 5;
                 }
                 _canMove = false;
                 Vector3 direction = transform.position - collision.transform.position;
                 transform.position = transform.position + direction;
                 _canTakeDamage     = false;
             }
         }
     }
     else if (collision.gameObject.tag == "Bullet")
     {
         if (_canTakeDamage)
         {
             HitPoints--;
             Destroy(collision.rigidbody);
             {
                 _canMove     = false;
                 _canAim      = false;
                 respawnDelay = Time.time + 5;
             }
             _canMove = false;
             Vector3 direction = transform.position - collision.transform.position;
             transform.position = transform.position + direction;
             _canTakeDamage     = false;
         }
     }
     else if (collision.gameObject.tag == "Revolver")
     {
         weapon = global::Weapon.revolver;
         Destroy(collision.gameObject);
     }
     else if (collision.gameObject.tag == "Shotgun")
     {
         weapon = global::Weapon.shotgun;
         Destroy(collision.gameObject);
     }
     else if (collision.gameObject.tag == "Exit")
     {
         Destroy(this.gameObject);
     }
 }
 void Fire()
 {
     if (state == TentacleState.idle)
     {
         state  = TentacleState.grabbing;
         target = _player._aim;
         if (Vector3.Distance(target, _player.tentaclePoint.transform.position) > maxRange)
         {
             Vector3 direction = GetDirection(target, _player.tentaclePoint.transform.position, maxRange);
             //Vector3 direction = target - _player.tentaclePoint.transform.position;
             //direction.Normalize();
             //direction *= maxRange;
             target = _player.tentaclePoint.transform.position + direction;
         }
         else if (Vector3.Distance(target, _player.tentaclePoint.transform.position) < minRange)
         {
             Vector3 direction = target - _player.tentaclePoint.transform.position;
             direction.Normalize();
             target = _player.tentaclePoint.transform.position + direction;
         }
     }
     else if (state == TentacleState.holding)
     {
         state  = TentacleState.throwing;
         target = _player._aim;
         Rigidbody rigBod = holding.GetComponent <Rigidbody>();
         rigBod.isKinematic = false;
         holding.layer      = 0;
         Vector3 direction = GetDirection(target, _player.transform.position, maxSpeed);
         rigBod.velocity = direction;
         if (holding.tag == "Enemy")
         {
             ParentEnemy enemy = holding.GetComponent <ParentEnemy>();
             enemy.isGrabbed = false;
         }
         else
         {
             rigBod.mass -= .01f;
             if (rigBod.mass < .98)
             {
                 Destroy(holding, 1);
             }
         }
     }
 }