Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by kymbers · Jan 11, 2021 at 02:14 PM · enemyenemy aienemiesenemy healthenemy damage

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

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<TextMesh>().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<TextMesh>().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<Collider2D>().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

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image kymbers · Jan 11, 2021 at 04:00 PM 0
Share

I solved the problem, thank you all!

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

161 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity2D Need Help in Multiple Enemies Shooting Script 0 Answers

Enemy dies in editor mode but not in build 2 Answers

How to rotate the enemy in 2D top down 0 Answers

How do I code transform translate in unity3d/ Not working right 0 Answers

i did a spawn script but when 2 identical enemies spawn and one attacks first, the other stops and starts the attacking animation too 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges