Ejemplo n.º 1
0
 // Update is called once per frame
 void Update()
 {
     if (Time.time >= nextFireballTime)
     {
         sfx.PlayEnemyAttack(gameObject.transform.position);
         nextFireballTime = Time.time + fireballCoolDown;
         var position = attackPos.position;
         //position.x = position.x * -1;
         GameObject spell = Instantiate(fireball,
                                        new Vector2(position.x + 2 * Mathf.Sign(gameObject.transform.localScale.x) * -1, position.y),
                                        Quaternion.identity);
         sfx.PlayFireBallSFX(position);
         PlayerFireBall spellController = spell.GetComponent <PlayerFireBall>();
         spellController.enemy = "Player";
         Vector3 spellScale = spell.transform.localScale;
         spell.transform.localScale = new Vector3(spellScale.x * Mathf.Sign(gameObject.transform.localScale.x) * -1,
                                                  spellScale.y, spellScale.z);
     }
 }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (!PauseMenu.IsPaused)
        {
            if (Input.GetButton("Fire1") && Time.time >= nextBasicAttackTime && player.GetComponent <PlayerController>().enableMoving)
            {
                nextBasicAttackTime = Time.time + basicAttackCoolDown;

                animator.SetTrigger(Attack);
                sfx.PlayChawaAttack(transform.position);
            }

            if (Input.GetButton("Fire2") && player.GetComponent <PlayerController>().enableMoving)
            {
                if (equipedSpell == spells.Fire && Time.time >= nextFireballTime)
                {
                    //Starts cooldown animation in HUD
                    _spellCooldownController.triggerSpell("fire");
                    nextFireballTime = Time.time + fireballCoolDown;
                    var        position = attackPos.position;
                    GameObject spell    = Instantiate(fireball, new Vector2(position.x + 2 * Mathf.Sign(gameObject.transform.localScale.x), position.y), Quaternion.identity);
                    sfx.PlayFireBallSFX(position);
                    PlayerFireBall spellController = spell.GetComponent <PlayerFireBall>();
                    spellController.enemy = "Enemy";
                    Vector3 spellScale = spell.transform.localScale;
                    spell.transform.localScale = new Vector3(spellScale.x * Mathf.Sign(gameObject.transform.localScale.x), spellScale.y, spellScale.z);
                    //Instantiate(fireball, attackPos.transform);
                }

                if (equipedSpell == spells.Ice && Time.time >= nextIceTime)
                {
                    //Starts cooldown animation in HUD
                    _spellCooldownController.triggerSpell("ice");
                    nextIceTime = Time.time + iceCoolDown;
                    var        position         = transform.position;
                    GameObject spell            = Instantiate(ice, new Vector2(position.x + 2 * Mathf.Sign(gameObject.transform.localScale.x), position.y), Quaternion.identity);
                    PlayerIce  spell1Controller = spell.GetComponent <PlayerIce>();
                    spell1Controller.enemy = "Enemy";
                    GameObject spell2           = Instantiate(ice, new Vector2(position.x + 2 * Mathf.Sign(gameObject.transform.localScale.x), position.y), Quaternion.identity);
                    PlayerIce  spell2Controller = spell2.GetComponent <PlayerIce>();
                    spell2Controller.enemy = "Enemy";
                    GameObject spell3           = Instantiate(ice, new Vector2(position.x + 2 * Mathf.Sign(gameObject.transform.localScale.x), position.y), Quaternion.identity);
                    PlayerIce  spell3Controller = spell3.GetComponent <PlayerIce>();
                    spell3Controller.enemy = "Enemy";

                    sfx.PlayIceSFX(position);
                    if (Mathf.Sign(transform.localScale.x) > 0)
                    {
                        spell2.GetComponent <Transform>().rotation = Quaternion.Euler(0, 0, iceAngle);
                        spell3.GetComponent <Transform>().rotation = Quaternion.Euler(0, 0, 360 - iceAngle);
                    }
                    else
                    {
                        spell.GetComponent <Transform>().rotation  = Quaternion.Euler(0, 0, 180);
                        spell2.GetComponent <Transform>().rotation = Quaternion.Euler(0, 0, 180 + iceAngle);
                        spell3.GetComponent <Transform>().rotation = Quaternion.Euler(0, 0, 180 - iceAngle);
                    }

                    Vector3 spellScale = spell.transform.localScale;
                    spell.transform.localScale = new Vector3(spellScale.x * Mathf.Sign(gameObject.transform.localScale.x), spellScale.y, spellScale.z);
                }

                if (equipedSpell == spells.Air && Time.time >= nextDashTime)
                {
                    //Starts cooldown animation in HUD
                    _spellCooldownController.triggerSpell("air");
                    nextDashTime = Time.time + dashCoolDown;
                    animator.SetBool("isDashing", true);
                    sfx.PlayAirDashSFX(transform.position);
                }
            }

            if (Input.GetButton("ChangeRight") && Time.time > nextSpellChange)
            {
                if (unlockedSpellCount > 1)
                {
                    nextSpellChange = Time.time + spellChangeCoolDown;
                    int index = Array.IndexOf(unlockedSpells, equipedSpell);
                    index = (index + 1) % unlockedSpellCount;

                    equipedSpell = unlockedSpells[index];
                }
            }

            if (Input.GetButton("ChangeLeft") && Time.time > nextSpellChange)
            {
                if (unlockedSpellCount > 1)
                {
                    nextSpellChange = Time.time + spellChangeCoolDown;
                    int index = Array.IndexOf(unlockedSpells, equipedSpell);
                    index = (index - 1) % unlockedSpellCount;
                    if (index == -1)
                    {
                        index = unlockedSpellCount - 1;
                    }
                    equipedSpell = unlockedSpells[index];
                }
            }

            if (animator.GetCurrentAnimatorStateInfo(0).IsName("Attack"))
            {
                Collider2D[] enemiesToDamage = Physics2D.OverlapCircleAll(attackPos.position, attackRange, whatIsEnemy);
                for (int i = 0; i < enemiesToDamage.Length; ++i)
                {
                    //enemiesToDamage[i].GetComponent<EnemyController>().takeDamage(damage);
                    if (enemiesToDamage[i].GetComponent <EnemyController>().enemyName.CompareTo("Aabbeell") == 0)
                    {
                        enemiesToDamage[i].GetComponent <EnemyController>().takeDamage(damage, damage /*Basic*/);
                    }
                    else
                    {
                        enemiesToDamage[i].GetComponent <EnemyController>().takeDamage(damage);
                    }
                }
            }
        }
    }