Ive added a script onto my enimes that makes it once they are destroyed they will respawn the rigidbody placed in “respawn” and at the spot “respawnpoint” my problem is that once respawned they are called “Clones” and after two respawns the enemy no longer has the scripts working… how do I edit this script to spawn my enemy not as a clone?
using UnityEngine;
using System.Collections;
public class AttackandHP : MonoBehaviour {
public int maxHealth = 10;
public int curHealth = 10;
public GameObject target;
public float attackTimer;
public float coolDown;
public float EXPGAIN = 20;
public GUIText DamagePoints;
public int damage = 0;
public Transform ptsPrefab;
public Rigidbody respawn;
public Transform respawnpoint;
public float healthBarLength;
// Use this for initialization
void Start () {
target = GameObject.FindGameObjectWithTag ("Player");
healthBarLength = Screen.width / 2;
attackTimer = 0;
coolDown = 2.0f;
}
// Update is called once per frame
void Update () {
AdjustCurrentHealth(0);
if(attackTimer > 0)
attackTimer -= Time.deltaTime;
if(attackTimer < 0)
attackTimer = 0;
if(attackTimer == 0) {
Attack();
attackTimer = coolDown;
}
}
void OnGUI() {
}
public void AdjustCurrentHealth(int odj) {
curHealth += odj;
if(curHealth < 1)
curHealth = 0;
if(curHealth > maxHealth)
curHealth = maxHealth;
if(maxHealth < 1)
maxHealth = 1;
if (curHealth == 0) {
Destroy (gameObject);
Rigidbody clone;
clone = Instantiate (respawn, respawnpoint.transform.position, respawnpoint.transform.rotation) as Rigidbody;
PlayerAttack ZS = (PlayerAttack)target.GetComponent ("PlayerAttack");
ZS.DeselectTarget ();
ZS.SpawnEXP();
PlayerHealth eh = (PlayerHealth)target.GetComponent ("PlayerHealth");
eh.AdjustCurrentEXP (20);
}