I’m having this issue where the master enemy will clone the enemies that go out on the play field, But then the clones will make clones of themselves, I only want the master to make clones, Here’s my code.
using UnityEngine;
using System.Collections;
public class ENAI : MonoBehaviour {
// Use this for initialization
// Update is called once per frame
void Update() {
int rndizer = Random.Range(1, 51);
if (rndizer == 1 ) {
Rigidbody clone;
clone = Instantiate (GameObject.Find("Enemy"), transform.position, transform.rotation) as Rigidbody;
clone.AddForce (Vector3.forward / 40);
}
}
}
public class ENAI : MonoBehaviour {
// Use this for initialization
public bool canSpawn = true;
// Update is called once per frame
void Update() {
if(canSpawn){
int rndizer = Random.Range(1, 51);
if (rndizer == 1 ) {
Rigidbody clone;
clone = Instantiate (GameObject.Find("Enemy"), transform.position, transform.rotation) as Rigidbody;
clone.AddForce (Vector3.forward / 40);
}
}
}
}
Then attach this to your clone prefab.
public class CloneScript : MonoBehaviour {
public bool AmIAClone = false;s
// Use this for initialization
// Update is called once per frame
void Update (){
if (AmIAClone == true) {
GetComponent<ENAI>().canSpawn = false;
}
}