Ejemplo n.º 1
0
    private IEnumerator Fire(float waitTime, int _dmg, float _arrowSpeed)
    {
        firing      = true;
        normVel     = rb.velocity;
        rb.velocity = Vector2.zero;

        attackTimer = Time.time + 9999f;
        anim.SetBool("firingNow", true);
        yield return(new WaitForSeconds(waitTime));

        GameObject arrowClone = Poolable.Get(() => Poolable.CreateObj(arrowPref.gameObject), arrowPool.NameOfKey);

        arrowClone.transform.position = firePos.position;
        arrowClone.transform.rotation = transform.rotation;

        AudioMaster.Instance.Play("ArrowFire");
        arrowClone.GetComponent <Rigidbody2D>().velocity = _arrowSpeed * transform.up * -1f;
        EnemyArrow enArrow = arrowClone.GetComponent <EnemyArrow>();

        enArrow.dmg      = _dmg;
        enArrow.lifeTime = arrowLifeTime + Time.time;
        if (objectContainer)
        {
            arrowClone.transform.parent = objectContainer;
        }
        anim.SetBool("firingNow", false);
        attackTimer = attackDelay + Time.time;

        rb.velocity = normVel;
        firing      = false;
    }
Ejemplo n.º 2
0
    /// <summary>
    /// This Function produces Arrows and seeks for its nearest by target.
    /// </summary>
    public void Shoot()
    {
        GameObject arrowGO = (GameObject)Instantiate(enemyArrowPrefab, firePoint.position, firePoint.rotation);
        EnemyArrow arrow   = arrowGO.GetComponent <EnemyArrow>();

        if (arrow != null)
        {
            arrow.Seek(target);
        }
    }
Ejemplo n.º 3
0
 public void SetBullet(BulletType type, Vector3 position, Vector3 direction)
 {
     if (type == BulletType.ARROW)
     {
         EnemyArrow arrow = Instantiate(arrowPrefab);
         arrow.transform.position    = position;
         arrow.transform.eulerAngles = direction;
         arrow.transform.Translate(arrow.transform.forward * 0.4f, Space.World);
         arrow.MoveBy(arrow.transform.forward * 2f, 0.3f);
     }
     else
     {
         EnemyBullet bullet = bulletPools[type].Dequeue();
         bullet.SetActive(true);
         bullet.transform.position         = position;
         bullet.transform.localEulerAngles = direction;
         bulletPools[type].Enqueue(bullet);
     }
 }
Ejemplo n.º 4
0
    private void Fire()
    {
        GameObject arrowClone = Poolable.Get(() => Poolable.CreateObj(arrowPref.gameObject), arrowPool.NameOfKey);

        arrowClone.transform.position = firePos.position;
        arrowClone.transform.rotation = transform.rotation;
        EnemyArrow enArrow = arrowClone.GetComponent <EnemyArrow>();

        arrowClone.GetComponent <Rigidbody2D>().velocity = arrowSpeed * transform.up * -1f;
        enArrow.lifeTime = arrowLifeTime + Time.time;
        enArrow.dmg      = dmg;

        AudioMaster.Instance.Play("ArrowFire");
        if (objectContainer)
        {
            arrowClone.transform.parent = objectContainer;
        }
        attackTimer = attackDelay + Time.time;
    }
    void Update()
    {
        //Prevents head from going up the player's butt
        if (transform.position.y < target.position.y)
        {
            sprite.sortingOrder = 4;
        }
        else
        {
            sprite.sortingOrder = 2;
        }

        isMoving         = false;
        distanceToPlayer = Vector2.Distance(transform.position, target.position);

        //Attack player if within attack range
        if (distanceToPlayer < attackRange && Time.time > lastAttack + attackDelay)
        {
            audio.PlayOneShot(bowSound);
            Vector2    facePlayer = target.position - transform.position;
            EnemyArrow newArrow   = Instantiate(arrow, transform.position, Quaternion.identity);
            newArrow.Dir(facePlayer);
            lastAttack = Time.time;
        }
        //Otherwise, chase player if within chase range
        else if (distanceToPlayer < chaseRange && distanceToPlayer > attackRange)
        {
            isMoving           = true;
            transform.position = Vector2.MoveTowards(transform.position, target.position, speed * Time.deltaTime);

            //Update positions for anim
            anim.SetFloat("MoveX", transform.position.x - lastMove.x);
            anim.SetFloat("MoveY", transform.position.y - lastMove.y);
            anim.SetFloat("LastMoveX", transform.position.x - lastMove.x);
            anim.SetFloat("LastMoveY", transform.position.y - lastMove.y);
            lastMove.Set(transform.position.x, transform.position.y);
        }

        anim.SetBool("IsMoving", isMoving);
    }
Ejemplo n.º 6
0
    void CheckIfVisible()
    {
        Vector3 EnemyPos = Camera.main.WorldToViewportPoint(this.transform.position);

        if (EnemyPos.x < 1f && EnemyPos.x > 0f && EnemyPos.y < 1f && EnemyPos.y > 0f)
        {
            if (EnemyArrow.GetComponent <SpriteRenderer>().enabled)
            {
                EnemyArrow.GetComponent <SpriteRenderer>().enabled = false;
            }
            //	Debug.Log (this.gameObject.name+" inview ");
        }
        else
        {
            if (!EnemyArrow.GetComponent <SpriteRenderer>().enabled)
            {
                EnemyArrow.GetComponent <SpriteRenderer>().enabled = true;
            }

            if (EnemyPos.x > 0.95f)
            {
                xarrowposvalue = 0.95f;
            }
            else if (EnemyPos.x < 0.05f)
            {
                xarrowposvalue = 0.05f;
            }
            else
            {
                xarrowposvalue = EnemyPos.x;
            }

            if (EnemyPos.y > 0.95f)
            {
                yarrowposvalue = 0.95f;
            }
            else if (EnemyPos.y < 0.05f)
            {
                yarrowposvalue = 0.05f;
            }
            else
            {
                yarrowposvalue = EnemyPos.y;
            }

            Vector3 ArrowPos = new Vector3(xarrowposvalue, yarrowposvalue, 10);
            EnemyArrow.transform.position = Camera.main.ViewportToWorldPoint(ArrowPos);


            float angle = Mathf.Rad2Deg * Mathf.Atan2(EnemyArrow.transform.position.x - this.transform.position.x, EnemyArrow.transform.position.y - this.transform.position.y);



            if (EnemyPos.x > 1 || EnemyPos.x < 0)
            {
                if (EnemyPos.y > 0 && EnemyPos.y < 1)
                {
                    EnemyArrow.transform.rotation = Quaternion.Euler(0, 0, 180 + angle);
                }
                else
                {
                    float changefixedangle = 0;
                    if (EnemyPos.y > 1)
                    {
                        changefixedangle = 1;
                    }
                    else
                    {
                        changefixedangle = -1;
                    }
                    if (EnemyPos.x < 0)
                    {
                        EnemyArrow.transform.rotation = Quaternion.Euler(0, 0, changefixedangle * 90 + angle);
                    }
                    else
                    {
                        EnemyArrow.transform.rotation = Quaternion.Euler(0, 0, changefixedangle * -90 + angle);
                    }
                }
            }
            else
            {
                EnemyArrow.transform.rotation = Quaternion.Euler(0, 0, angle);
            }
        }
    }