IEnumerator RepeatShooting()
    {
        BulletBehavior bullet = Instantiate(bulletPrefab, transform.position, Quaternion.identity);

        if (isShootingHorizontally)
        {
            bullet.GetComponent <BulletBehavior>().SpeedOfBullet(bulletSpeedX, 0);
        }
        else
        {
            bullet.GetComponent <BulletBehavior>().SpeedOfBullet(0, bulletSpeedY);
        }

        yield return(new WaitForSeconds(repeatTimer));
    }
Esempio n. 2
0
    void handleShoot()
    {
        if (shootyPoint == null)
        {
            return;
        }
        Vector2 shootDir = getShoot();

        if (Time.fixedTime - lastShot >= bulletCooldown &&
            (autoFire || shootDir.magnitude < ggd.accuracyLimit))
        {
            canShoot = true;
        }
        if (canShoot && bulletTemplate != null && shootDir.magnitude > ggd.accuracyLimit)
        {
            canShoot = false;
            lastShot = Time.fixedTime;
            GameObject     go      = GameObject.Instantiate(bulletTemplate.gameObject);
            BulletBehavior created = go.GetComponent <BulletBehavior>();
            if (shootDir.x < 0)
            {
                created.initVel            = shootDir * shootyForce;
                created.transform.position = new Vector2(transform.position.x - shootyPoint.localPosition.x,
                                                         transform.position.y);
                go.GetComponent <SpriteRenderer>().flipX = true;
            }
            else
            {
                created.initVel            = shootDir * shootyForce;
                created.transform.position = shootyPoint.position;
            }
            created.GetComponent <Rigidbody2D>().velocity = rb2.velocity;
            audioManager.playClipHere("shoot", transform.position);
        }
    }