0
\$\begingroup\$

I made the game space shooter. In my game the boss take too much time to fire and the enemy not even come in the screen. So how to manage the fire speed and make the level tough.Click the link on 2 and 3 also for image view.

shootscript. cs

using UnityEngine;
using System.Collections;

public class ShootScript : MonoBehaviour {

    public int dammage = 1;
    public bool isEnemyShot = false;
    public Sprite lightDestroy;
    public float laserTime;
    private float increament;


    void Update()
    {
        laserTime -= Time.deltaTime;
        if (laserTime <= 0) {
            Destroy(gameObject);
        }
    }


    void FixedUpdate()
    {
        if (!isEnemyShot) {
            this.transform.Translate (Vector2.up * 6 * Time.deltaTime);
        } else {
            this.transform.Translate (Vector2.up * -6 * Time.deltaTime);
        }
    }

    void OnCollisionEnter2D( Collision2D coll)
    {
        if (coll.gameObject.tag == "Player" || coll.gameObject.tag == "Enemy") 
        {
            gameObject.transform.localScale = new Vector2 (1, 1);
            gameObject.GetComponent<SpriteRenderer> ().sprite = lightDestroy;
            gameObject.GetComponent<BoxCollider2D> ().isTrigger = true;
            Destroy (gameObject, 0.05f);
        } else {
            Destroy(gameObject);
        }
    }
}

Weapon.cs

using UnityEngine;
using System.Collections;

public class Weapon : MonoBehaviour {

    public Transform laserPrefab ;
    public bool isEnemyWeapon = false;
    public float shootDelay = 1.0f;
    private float waitToShoot;

    public bool firingContinously = true;
    float nextFire = 0;
    float fireDelay = 400; // 100 milliseconds between each bullet


    void Start () {
        waitToShoot = 0f;
        firingContinously = true;
    }

    void Update () {
        if(Input.GetKeyDown(KeyCode.G)){
            firingContinously = !firingContinously;
        }

        if(firingContinously && !isEnemyWeapon)
        {
            if(Time.time * 1000 > nextFire){
                nextFire = (Time.time * 1000) + fireDelay;
                Fire();
            }
        }


        if (waitToShoot > 0) {
            waitToShoot = Time.deltaTime;      

        }

        if (Input.GetKeyDown (KeyCode.Space) && isEnemyWeapon == false) {
            Fire ();
        }   

        if (isEnemyWeapon == true && EnemyAttack == true) {
            waitToShoot = shootDelay;
            var shootLaser = Instantiate (laserPrefab) as Transform;
            Vector2 pos = shootLaser.transform.position;
            pos.x = transform.position.x ;
            pos.y = transform.position.y - 0.1f;
            shootLaser.transform.position = pos;
//          SoundHelper.instanceSound.EnemyLaserSound();

        }
    }


    public void Fire()
    {
        var shootLaser = Instantiate(laserPrefab) as Transform;
        Vector2 pos = shootLaser.transform.position;
        pos.x = transform.position.x;
        pos.y = transform.position.y + 0.5f;
        shootLaser.transform.position = pos;
        //SoundHelper.instanceSound.PlayerLaserSound();
        Debug.Log("Fire Method");


    }

    public bool EnemyAttack
    {
        get
        {
            return waitToShoot <= 0f;
        }
    }
}

[Enemy Laser[![enemy][1[Boss Laser[Boss]2]3

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

If I am correct, your enemy will never shoot because Time.deltaTime is never <= 0. But that could simply be a typo here on Stackoverflow. So make sure you use

if (waitToShoot > 0) {
    waitToShoot -= Time.deltaTime;

instead of

if (waitToShoot > 0) {
    waitToShoot = Time.deltaTime;

And to achieve a higher fire rate from the boss you can change shootDelay to a smaller number.

And to make the level though I guess there are like a thousand possibilities. I would make some special bullets like those you can see in some bullet hell games (e.g. bullets that spawn new bullets in different directions, faster bullets, etc.) and give the boss a lot of health so you really have to battle him for a while and you have to avoid a lot of bullets. Maybe you can add some smaller enemies as well if your boss is too weak or shoots too less bullets. Something like this.

\$\endgroup\$

You must log in to answer this question.