so i have prefab called “enemy” and in that enemy have a script named “enemyBlue_script”. and also i have 1 another script called rulebase and it attached to gameobject " game_controller" . in that rulebase script i have some method , one of them is fire() method. and i tried to call it in the enemyBlue_script in the update() function. when i run the game the enemy can firing but the other enemy can’t. when the enemy which can fire has destroyed then the other enemy can fire.
this is my script
rulebase script
using UnityEngine;
using System.Collections;
public class Rulebase : MonoBehaviour {
public float fireRate = 5F;
public GameObject shot;
private float nextFire = 0.0F;
public void Fire(Transform shotSpawn){
if (Time.time > nextFire) {
nextFire = Time.time +fireRate; //Increment nextFire time with the current system time + fireRate
Instantiate (shot, shotSpawn.position, shotSpawn.rotation); //Instantiate fire shot
}
}
}
and this is enemyBlue_script which called the fire function from the rulebase script
using UnityEngine;
using System.Collections;
public class EnemyBlue_Script : MonoBehaviour
{
public Transform shotSpawn;
void Update(){
Rules.Fire (shotSpawn);
}
the result of that script is something like this
as you can see the other enemy wont fire. thanks for the help