Example #1
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.tag.Equals("bullet"))
        {
            return;
        }

        m_isMoving = false;

        IDamagable damagable = collision.GetComponent <IDamagable>();

        if (damagable != null)
        {
            Creature creature = damagable as Creature;
            if (creature != null && creature == m_owner)
            {
                m_isMoving = true;
                return;
            }

            damagable.DoDamage(Damage);
        }

        DoDestroy();
    }
    private void OnCollisionEnter(Collision collision)
    {
        IDamagable damageReceiver = collision.gameObject.GetComponentInParent <IDamagable>();

        if (damageReceiver != null)
        {
            damageReceiver.DoDamage(damageAmount);
        }

        DisableSelf();
    }
Example #3
0
    /// <summary>
    /// Register bullet collisions
    /// </summary>
    /// <param name="_collision"></param>
    private void OnCollisionEnter(Collision _collision)
    {
        IDamagable damagable = _collision.gameObject.GetComponent <IDamagable>();

        if (damagable != null)
        {
            //If collision has IDamagable
            damagable.DoDamage(bulletScriptable.damage);
        }

        gameObject.SetActive(false);
    }
Example #4
0
        public void Update(int ticks)
        {
            _xTicks += ticks;
            _yTicks += ticks;


            while (_xTicks >= XRate || _yTicks >= YRate)
            {
                int dX = 0;
                int dY = 0;
                if (_xTicks >= XRate)
                {
                    dX       = XSign;
                    _xTicks -= XRate;
                }

                if (_yTicks >= YRate)
                {
                    dY       = YSign;
                    _yTicks -= YRate;
                }

                Coord newPos = Parent.Position + new Coord(dX, dY);
                if (Parent.CurrentMap?.GetEntity <IGameObject>(newPos, Parent.CurrentMap.LayerMasker.Mask(Parent.Layer)) is IGameObject collideWith)
                {
                    OnCollide?.Invoke(collideWith);
                    _destroyOnCollide?.DoDamage(new Damage(int.MaxValue));
                    break;
                }

                if (!Parent.CurrentMap?.WalkabilityView[newPos] ?? false)
                {
                    OnCollide?.Invoke(Parent.CurrentMap.GetObject(newPos));
                    _destroyOnCollide?.DoDamage(new Damage(int.MaxValue));
                    break;
                }

                Parent.Position = newPos;
            }
        }
 void OnCollisionEnter(Collision col)
 {
     if (physicsEnabled)
     {
         IDamagable damagable = (IDamagable)(col.gameObject.GetComponent(typeof(IDamagable)));
         if (damagable != null)
         {
             damagable.DoDamage(1f);
         }
         startExplosion();
         applyExplosiveForce(.5f);
         this.kill();
     }
 }
Example #6
0
    void Shoot()
    {
        Ray ray = camera.ScreenPointToRay(Input.mousePosition);

        RaycastHit hitInfo;

        if (Physics.Raycast(ray, out hitInfo))
        {
            Debug.Log(hitInfo.collider.gameObject.name);

            IDamagable target = hitInfo.collider.gameObject.GetComponent <IDamagable>();
            if (target != null)
            {
                target.DoDamage(1);
            }
        }
    }
    void Update()
    {
        if (Input.GetButtonDown("Jump"))
        {
            Collider[] colliders = Physics.OverlapSphere(transform.position, transform.localScale.x / 2f);

            for (int i = 0; i < colliders.Length; i++)
            {
                IDamagable damagable = colliders[i].GetComponent <IDamagable>();

                if (damagable != null)
                {
                    damagable.DoDamage(damageAmount);
                }
            }
        }
    }