3
The enemy ship simply can’t shoot and walk at the same time, or it does one or the other.
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 within it I created two more hitR
and hitL
That’s where the shots come from, the script EnemyGunScript
is in the gun
and the gun
in the enemy ship. Please help me, if you know a possible solution in tmb javascript serves.
I don’t understand, the code ta in c# but you want the solution in javascript???
– user28595
If someone knows any possible solution, regardless if it is in C# or Javascript
– Thays