Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

How To Destroy/Deactivate one enemy without affecting other enemies of the same type?

$
0
0
Hi, I have a problem, I have a universal enemy script, which I use on all enemies, but as in the script when an enemy dies it is set to deactivate the current script and because of that the first enemy goes perfectly to kill him, but when I arrive at the second I can't attack him because he says the script is disabled and he can't access it, how can I do when I kill an enemy not to affect the main script of all enemies? public void TakeDamage(int damage) { currentHealth -= damage; anim.SetTrigger("TakeHit"); if (currentHealth == 80) { heartRightOne.SetActive(false); } else if (currentHealth == 60) { heartRightOne.SetActive(false); heartRightTwo.SetActive(false); } else if (currentHealth == 40) { heartRightOne.SetActive(false); heartRightTwo.SetActive(false); heartMiddle.SetActive(false); } else if (currentHealth == 20) { heartRightOne.SetActive(false); heartRightTwo.SetActive(false); heartMiddle.SetActive(false); heartLeftTwo.SetActive(false); } else if (currentHealth <= 0) { Die(); heartRightOne.SetActive(false); heartRightTwo.SetActive(false); heartMiddle.SetActive(false); heartLeftTwo.SetActive(false); heartLeftOne.SetActive(false); } //Check if the enemy is facingRight or not to display the damage text popup; if (facingRight == true) { GameObject go = Instantiate(damageText, transform.position, Quaternion.identity); go.GetComponent().text = damage.ToString(); go.transform.SetParent(gameObject.transform); go.transform.localPosition += new Vector3(Random.Range(-textPositionX, textPositionX), Random.Range(+textPositionY, 2), Random.Range(0, 0)); } else if (!facingRight) { GameObject go = Instantiate(damageText, transform.position, Quaternion.identity); go.GetComponent().text = damage.ToString(); go.transform.SetParent(gameObject.transform); go.transform.localPosition += new Vector3(Random.Range(-textPositionX, textPositionX), Random.Range(+textPositionY, 2), Random.Range(0, 0)); } } public void Die() { //Set The Animation For Dead and Stop all other functions / animations; anim.SetBool("Dead", true); //Instantiate a Gold Prefab; GameObject gold = Instantiate(goldPrefab, transform.position, Quaternion.identity); gold.transform.SetParent(gameObject.transform); gold.transform.localPosition = new Vector2(0, goldPositionY); gold.transform.localScale = new Vector2(localScaleX, localScaleY); //Set Player +25 Experience; experience.IncraeseExp(25); //Deactivate The Enemy Collider; GetComponent().enabled = false; //Destroy The Enemy AI; Destroy(hotZone); Destroy(triggerArea); Destroy(hitBox); Destroy(enemyHearts); //Deactivate The Current Enemy Script; this.enabled = false; } Because the script is done this way, when I go to attack the second enemy, I can't kill him anymore If help I can make a video to show the entire script bcs its a big one and to show exactly the problem

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>