Example #1
0
 public void basicAttack()
 {
     if (!cooldowns[0])
     {
         StartCoroutine(jab());
         int sound_determiner = Random.Range(0, 9);
         if (sound_determiner <= 4)
         {
             SoundManagerScript.PlaySound("ATK1");
         }
         else
         {
             SoundManagerScript.PlaySound("ATK2");
         }
         RaycastHit2D[] hits = Physics2D.BoxCastAll(wielder.position, Vector2.one, 0f, attackDir, 1f);
         ExtDebug.DrawBoxCast2D(wielder.position, Vector2.one, 0f, attackDir, 1f, Color.blue, 1f);
         foreach (RaycastHit2D hit in hits)
         {
             if (hit.transform.CompareTag("Enemy"))
             {
                 hit.transform.GetComponent <Enemy>().takeDamage(damage);
                 damage = 7;
             }
         }
         StartCoroutine(FadeTo(1f, cooldown, 0, cooldownImage));
     }
 }
Example #2
0
    IEnumerator Attack()
    {
        Vector2 direction = player.position - transform.position;

        currDirection = direction;
        //Slime winds up.
        Debug.Log("Slime prepares to attack!");
        float elapsed_time = 0.0f;

        while (elapsed_time <= 1.0f)
        {
            elapsed_time += Time.deltaTime;
            yield return(null);
        }

        //Play SFX
        //FindObjectOfType<AudioManager>().Play("HitSFX");

        int attack_determiner = Random.Range(0, 9);

        if (attack_determiner <= .3)
        {
            Debug.Log("Slime attacks with spitball!");
            Instantiate(SpitBall, transform.position, Quaternion.identity);
        }
        else
        {
            Debug.Log("Slime attacks with headbutt!");
            //RaycastHit2D[] hits = Physics2D.CircleCastAll(transform.position, hitRadius, Vector2.zero);
            Vector2        hitbox = new Vector2(0.5f, 0.5f);
            RaycastHit2D[] hits   = Physics2D.BoxCastAll((Vector2)transform.position, hitbox, 0f, currDirection, 1f);
            ExtDebug.DrawBoxCast2D((Vector2)transform.position, hitbox, 0f, currDirection, 1f, Color.red, 1f);

            foreach (RaycastHit2D hit in hits)
            {
                if (hit.transform.CompareTag("Player"))
                {
                    Debug.Log("Hit player with headbutt in direction " + currDirection);
                    hit.transform.GetComponent <playerTest>().takeDamage(damageDealt);
                }
            }
        }
        timeBetweenAttacks = 5.0f;
        attacking          = false;
    }