private void OnTriggerStay2D(Collider2D collision)
    {
        if (collision.gameObject.CompareTag("Player"))
        {
            enemyStateMashine.state = EnemyStateMashine.State.Idle;
            enemyStateMashine.setStatebehaviour();

            if (attakable)
            {
                enemyStateMashine.state = EnemyStateMashine.State.Attaking;
                enemyStateMashine.setStatebehaviour();
                StartCoroutine(AttakingDuration(collision.transform.position));
            }
        }
    }
Example #2
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.gameObject.CompareTag("Player") && attakable)
     {
         StartCoroutine(AttakCooldown());
         if (collision.transform.position.y >= transform.parent.position.y)
         {
             anim.SetBool("PlayerUp", true);
         }
         else
         {
             anim.SetBool("PlayerUp", false);
         }
         enemyStateMashineScript.state = EnemyStateMashine.State.Attaking;
         enemyStateMashineScript.setStatebehaviour();
     }
 }
Example #3
0
    public override IEnumerator DamageCharacter(float damage, float interval, Vector3 position)
    {
        if (effectAvailable)
        {
            effectAvailable = false;
            InstantiateBlood(position);
            InstantiateHit(position);
            StartCoroutine(EffectCooldown());
        }
        rigidbody2D.AddForce(new Vector2(transform.position.x - position.x, transform.position.y - position.y).normalized *damage *damage * 50);
        while (true)
        {
            if (enemyStateMashineScript)
            {
                enemyStateMashineScript.state = EnemyStateMashine.State.Affected;
                enemyStateMashineScript.setStatebehaviour();
            }
            StartCoroutine(FlickerCharacter());
            hitPoints = hitPoints - damage;

            if (hitPoints <= float.Epsilon)
            {
                if (cameraShake)
                {
                    cameraShake.Shake(damage * 10, damage * 5, 0.2f);
                }
                InstantiateDeath(position);
                SpawnReward();
                KillCharacter();
                break;
            }
            cameraShake.Shake(damage * 4, damage * 2, 0.1f);

            if (interval > float.Epsilon)
            {
                yield return(new WaitForSeconds(interval));
            }
            else
            {
                break;
            }
        }
    }