public void Attack(bool isPlayer)
    {
        if (CanAttack)
        {
            shootCooldown = shootingRate;

            // Create a new shot
            var shotTransform = Instantiate(shotPrefab) as Transform;
            Destroy(shotTransform.gameObject, 2f);

            // Assign position
            shotTransform.position = transform.position;

            // The is enemy property
            Enemy_Shoot shot = shotTransform.gameObject.GetComponent <Enemy_Shoot>();
            if (shot != null)
            {
                shot.isPlayerShot = isPlayer;
            }

            // Fireball Movement
            Shoot_move move = shotTransform.gameObject.GetComponent <Shoot_move>();

            if (!move)
            {
                move.direction = this.transform.right;
            }
            else
            {
                // Change the facing and direction of fireball
                var player    = GameObject.Find("Level/2-Foreground/Player");
                var direction = (player.transform.position - transform.position).normalized;
                move.direction = direction;

                if (transform.localScale.x < 0)
                {
                    move.transform.localScale = new Vector3(-1f, move.transform.localScale.y, move.transform.localScale.z);
                }
                else
                {
                    move.transform.localScale = new Vector3(1f, move.transform.localScale.y, move.transform.localScale.z);
                }
            }
        }
    }
Ejemplo n.º 2
0
    private void OnTriggerEnter2D(Collider2D collider)
    {
        Enemy_Shoot shoot = collider.gameObject.GetComponent <Enemy_Shoot>();

        if (shoot != null)
        {
            if (shoot.isPlayerShot != isPlayer)
            {
                PlayerScript.hp -= shoot.damage;
                Destroy(shoot.gameObject);

                //if (PlayerScript.hp <= 0)
                //{
                //    Destroy(gameObject);
                //}
                //print(PlayerScript.hp);
            }
        }

        GainHP hp = collider.gameObject.GetComponent <GainHP>();

        if (hp != null)
        {
            if (hp.isHeal != isPlayer && hp.maxHeal > PlayerScript.hp)
            {
                PlayerScript.hp += hp.heal;

                print(PlayerScript.hp);
                Destroy(hp.gameObject);
            }
        }


        buff1 buff = collider.gameObject.GetComponent <buff1>();

        if (buff != null)
        {
            if (buff.isCatch == false)
            {
                PlayerScript.buffOn = true;
                Destroy(buff.gameObject);
            }
        }
    }
Ejemplo n.º 3
0
 // Use this for initialization
 void Awake()
 {
     _enemyshoot = GetComponent <Enemy_Shoot>();
 }