Example #1
0
    public void Fire()
    {
        if (Time.time > nextFire)
        {
            nextFire = Time.time + fireRate;

            sound.ShootSound();

            var bullet = (GameObject)Instantiate(bulletPrefab, bulletSpawn.position, bulletSpawn.rotation);

            bullet.GetComponent <Rigidbody2D>().velocity = bullet.transform.right * 20;

            Destroy(bullet, 3.0f);
        }
    }
Example #2
0
    public void Fire()
    {
        if (Time.time > nextFire)
        {
            nextFire = Time.time + fireRate;

            sound.ShootSound();

            // Create the Bullet from the Bullet Prefab
            var bullet = (GameObject)Instantiate(bulletPrefab, bulletSpawn.position, bulletSpawn.rotation);

            // Add velocity to the bullet
            bullet.GetComponent <Rigidbody2D>().velocity = bullet.transform.right * 20;

            // Destroy the bullet after x seconds
            Destroy(bullet, 3.0f);
        }
    }