Пример #1
0
    // Update is called once per frame
    void Update()
    {
        //shoots with random firerate
        float probability = Time.deltaTime * 1 / shotsDelay;

        if (Random.value < probability)
        {
            if (currentCoroutine != null)
            {
                StopCoroutine(currentCoroutine);
            }
            //get current coroutine
            currentCoroutine = BurstFire(firingRate);
            StartCoroutine(currentCoroutine);
            //play sound effect
            shootSound.PlaySoundEffect();
            timestamp = 0f;
        }

        if (ammo <= 0)
        {
            StopCoroutine(currentCoroutine);
            ammo = ammunition;
        }
    }
    //creates a nova of bullets
    void Nova()
    {
        Vector3 localShotPos = new Vector3(0, -((new Vector2(transform.localScale.x * offset,
                                                             transform.localScale.y * offset)).magnitude));

        //calculates degree intervals based on number of shots
        float degree = 360f / numberOfShots;

        for (float i = -180f; i < 180f; i += degree)
        {
            Quaternion rotation = Quaternion.AngleAxis(i, transform.forward);
            //calculate position to instantiate the projectile
            Vector3    shotPosition = transform.position + rotation * localShotPos;
            Projectile beam         = (Projectile)Instantiate(projectile, shotPosition, rotation * transform.rotation);

            //calculate vector x and y by using angle
            velocityOnX = Mathf.Sin((i * Mathf.PI) / 180);
            //convert actual degrees to radians
            velocityOnY = Mathf.Cos((i * Mathf.PI) / 180);

            beam.GetComponent <Rigidbody2D>().velocity = new Vector2(velocityOnX * projectileSpeed, -velocityOnY * projectileSpeed);
        }

        //play sound effect. Sound effect should be played only once
        boomSound = GetComponent <ShootSoundController>();
        boomSound.PlaySoundEffect();
    }
Пример #3
0
    //Method that handles shooting of the space weapon
    protected virtual void Shoot()
    {
        //instantiate beam at the position of fire point
        GameObject beam = (GameObject)Instantiate(projectile, transform.position, Quaternion.identity);

        beam.GetComponent <Rigidbody2D>().velocity = new Vector2(0f, projectileSpeed);
        //play sound effect of shooting
        shootSound.PlaySoundEffect();
    }
Пример #4
0
    void Shoot()
    {
        //instantiate beam at the position of fire point
        GameObject beam = (GameObject)Instantiate(projectile, firePoint.position, Quaternion.identity);

        //projectile speed is - in order to projectile flight towards the player (down)
        beam.GetComponent <Rigidbody2D>().velocity = new Vector2(0f, -projectileSpeed);
        //play sound effect
        shootSound.PlaySoundEffect();
    }