Exemplo n.º 1
0
    public IEnumerator BurstFire()
    {
        shooting = true;
        yield return(new WaitForSeconds(delayShoot));

        i = 0;
        while (i <= burstCount)
        {
            blockAnimator.SetInteger("AnimState", 3);   //fire
            gunAnimator.SetInteger("AnimState", 3);     //fire
            if ((i / 2f) == Mathf.Floor(i / 2f))        //if even
            {
                upDown = 1;
            }
            else
            {
                upDown = -1;
            }
            j = i;
            if (j > maxInt)
            {
                j = maxInt;
            }
            fDir        = tipTran.position - barrelTran.position;
            fDir        = Vector3.Normalize(fDir);
            shootAngle  = Vector3.Angle(Vector3.right, fDir);
            shootAngle += upDown * Random.Range(0, 100) * .02f * (j - 1);
            fDirHold    = new Vector3(Mathf.Cos(shootAngle * Mathf.Deg2Rad), Mathf.Sin(shootAngle * Mathf.Deg2Rad), 0f);

            if (transform.eulerAngles.z >= 180f || transform.eulerAngles.z <= -180f)
            {
                fDirHold *= -1;
            }
            turretSpot = tipTran.position;
            playNum    = Random.Range(1, 5);
            switch (playNum)
            {
            case 1:
                shot1.Play();
                break;

            case 2:
                shot2.Play();
                break;

            case 3:
                shot3.Play();
                break;

            case 4:
                shot4.Play();
                break;

            case 5:
                shot5.Play();
                break;
            }
            bullet = Instantiate(Resources.Load(bulletPath), turretSpot, Quaternion.identity) as GameObject;
            smallBulletsHurtScript = bullet.GetComponent <SmallBulletsHurt>();
            if (super)
            {
                smallBulletsHurtScript.blockType = 12;
            }
            else
            {
                smallBulletsHurtScript.blockType = 11;
            }
            bullet.transform.localScale *= 3;
            bullet.rigidbody2D.AddForce(fDirHold * fireForce);
            i++;
            bulletCount--;
            yield return(new WaitForSeconds(timebtShots));
        }
        blockAnimator.SetInteger("AnimState", 1);      //still
        gunAnimator.SetInteger("AnimState", 1);        //still
        if (bulletCount <= 0)
        {
            StartCoroutine(SelfDestruct());
        }
        shooting = false;
        if (!super)
        {
            StartCoroutine(BurstFire());
        }
    }
Exemplo n.º 2
0
    public IEnumerator BurstFire()
    {
        shooting = true;
        yield return new WaitForSeconds (delayShoot);
        i=0;
        while (i<=burstCount){
            blockAnimator.SetInteger("AnimState",3); //fire
            gunAnimator.SetInteger("AnimState",3); //fire
            if ((i/2f)==Mathf.Floor(i/2f)){ //if even
                upDown = 1;
            }
            else{
                upDown = -1;
            }
            j=i;
            if (j>maxInt){
                j=maxInt;
            }
            fDir = tipTran.position - barrelTran.position;
            fDir = Vector3.Normalize (fDir);
            shootAngle = Vector3.Angle(Vector3.right,fDir);
            shootAngle += upDown * Random.Range(0,100) * .02f * (j-1);
            fDirHold = new Vector3( Mathf.Cos(shootAngle * Mathf.Deg2Rad), Mathf.Sin(shootAngle * Mathf.Deg2Rad),0f);

            if (transform.eulerAngles.z>=180f || transform.eulerAngles.z<=-180f){
                fDirHold *= -1;
            }
            turretSpot = tipTran.position;
            playNum = Random.Range(1,5);
            switch (playNum){
            case 1:
                shot1.Play();
                break;
            case 2:
                shot2.Play();
                break;
            case 3:
                shot3.Play();
                break;
            case 4:
                shot4.Play();
                break;
            case 5:
                shot5.Play();
                break;
            }
            bullet = Instantiate (Resources.Load (bulletPath), turretSpot, Quaternion.identity) as GameObject;
            smallBulletsHurtScript = bullet.GetComponent<SmallBulletsHurt>();
            if (super){
                smallBulletsHurtScript.blockType = 12;
            }
            else{
                smallBulletsHurtScript.blockType = 11;
            }
            bullet.transform.localScale *= 3;
            bullet.rigidbody2D.AddForce (fDirHold * fireForce);
            i++;
            bulletCount--;
            yield return new WaitForSeconds(timebtShots);
        }
        blockAnimator.SetInteger("AnimState",1); //still
        gunAnimator.SetInteger("AnimState",1); //still
        if (bulletCount <= 0) {
            StartCoroutine(SelfDestruct());
        }
        shooting = false;
        if (!super) {
            StartCoroutine (BurstFire ());
        }
    }