The enemy ship simply can not shoot and walk at the same time, or it does one thing or another.
public class EnemyScript : MonoBehaviour {
public float speed = 5f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Vector2 min = Camera.main.ViewportToWorldPoint(new Vector2(0,0));
transform.Translate (new Vector3(0,1,0) * speed* Time.deltaTime);
if (transform.position.y < min.y) {
Destroy(gameObject);
}
}
}
ublic class EnemyGunScript : MonoBehaviour {
public GameObject HitL;
public GameObject HitR;
public GameObject EnemyBullet;
public float nextFire = 1f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Invoke("FireEnemyBullet", 1f);
}
void FireEnemyBullet(){
GameObject playerShip = GameObject.Find ("Player");
if (playerShip != null && Time.time*3 >= nextFire) {
GameObject bullet01 = (GameObject)Instantiate (EnemyBullet);
bullet01.transform.position = HitL.transform.position;
GameObject bullet02 = (GameObject)Instantiate (EnemyBullet);
bullet02.transform.position = HitR.transform.position;
//Vector2 direction = playerShip.transform.position - bullet.transform.position;
//bullet01.GetComponent<EnemyBullet>().SetDirection(direction);
//nextFire += Time.time/3;
nextFire += 1.5f;
}
}
}
I created a GameObject
called gun
and inside it I created two more hitR
and hitL
q is where the shots exit, the EnemyGunScript
script is in gun
and gun
in the enemy ship. Please help me if you know a possible solution in javascript tmb serves.