here is my code, if anyone can help, please and thank you.
using UnityEngine;
using System.Collections;
public class EnemyBehaviour : MonoBehaviour {
public GameObject projectile;
public float projectileSpeed = 5f;
public float health = 300f;
public float shotsPerSecond = 0.5f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
float probability = Time.deltaTime * shotsPerSecond;
if (Random.value < probability); {
Fire ();
}
}
void Fire () {
Vector3 startPosition = transform.position + new Vector3 (0, -1, 0);
GameObject missile = Instantiate (projectile, startPosition, Quaternion.identity) as GameObject;
missile.rigidbody2D.velocity = new Vector3 (0, -projectileSpeed, 0);
}
//Destroy collider
void OnTriggerEnter2D (Collider2D collider) {
Projectile missile = collider.gameObject.GetComponent <Projectile>();
if (missile) {
health -= missile.GetDamage ();
missile.Hit ();
if (health <= 0) {
Destroy (gameObject);
Debug.Log ("Hit by a projectile");
}
}
}
}