private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.collider.tag == "Player")
        {
            if (!playerHealthSystem.touchedToEnemy) // not touched or touchTime is still counting
            {
                playerHealthSystem.touchedToEnemy = true;

                playerHealthSystem.TakeDamage(touchDamage);

                attackDirection = transform.position - collision.transform.position;
                attackDirection = -attackDirection;

                if (attackDirection.x > 0)          //These are setting hurt vectors
                {
                    attackDirection.x = 1;
                }
                else if (attackDirection.x < 0)
                {
                    attackDirection.x = -1;
                }

                attackDirection.y    = 1;
                hurtForceTimeCounter = hurtForceTime;


                playerObject.GetComponent <HurtForceVariables>().inHurtForce = true;
            }
        }
    }
示例#2
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.CompareTag("Player"))
        {
            playerHealthSystem.TakeDamage(damage);

            attackDirection = transform.position - collision.transform.position;
            attackDirection.Normalize();
            attackDirection = -attackDirection;

            if (attackDirection.x > 0)
            {
                attackDirection.x = 1;
            }
            else if (attackDirection.x < 0)
            {
                attackDirection.x = -1;
            }

            hurtForceTimeCounter = hurtForceTime;
        }
    }