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;
}
}
}