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 JustinArmstrong · Sep 08, 2020 at 04:41 AM · duplicatedeathenemy health

Duplicated Enemy Deaths

So, I have been working for a couple weekends on this project to have the ground works laid out for what will be my first real game. I had everything all ready to go, but I just had to go and test one more thing. I duplicated my enemy, and now am coming across the classic case of all my like enemies dying simultaneously. As far as I can tell, it is not the issue of a static variable, although I have been known to be wrong before. I tried to find an answer before making this post, but either I am dumb or there has not been a whole lot of luck for people with this problem when it was not caused be an unneeded "static". The first code is the primary one that deals with the majority of the enemy behavior. The second one specifically deals with combat behavior. If anyone can see the point where I am simply being blind, that would be most appreciated.

 using System.Collections;
 using System.Collections.Generic;
 using System.Security.Cryptography;
 using UnityEngine;
 
 public class SpiderEnemy : MonoBehaviour
 {
 
     public int EnemyHealth = 10;
     public GameObject TheSpider;
     public int SpiderStatus;
     public int BaseXP = 10;
     public int CalculatedXP;
     public static int Spider;
     public GameObject ThePlayer;
     public GameObject AttackSphere;
     public GameObject DetectSphere;
     public int RespawnX;
     public int RespawnY;
     public int RespawnZ;
     public int EnemyArmor = 0;
 
     void Update()
     {
         TheSpider.transform.LookAt(ThePlayer.transform);
 
         if (InflictDamage.DeductPoints == true)
         {
             EnemyHealth -= InflictDamage.DamageAmount;
         }
 
         Spider = SpiderStatus;
 
         if(EnemyHealth <= 0)
         {
             if (SpiderStatus == 0)
             {
                 StartCoroutine(DeathSpider());
             }
 
         }
     }
 
     IEnumerator DeathSpider()
     {
         SpiderStatus = 6;
         CalculatedXP = BaseXP;
         yield return new WaitForSeconds(0.5f);
         TheSpider.GetComponent<Animation>().Play("die");
         AttackSphere.SetActive(false);
         Experience.CurrentXP += CalculatedXP;
         GoldCount.GoldValue += 1;
         yield return new WaitForSeconds(3.0f);
         TheSpider.transform.position = new Vector3(RespawnX, RespawnY, RespawnZ);
         yield return new WaitForSeconds(1.0f);
         EnemyHealth = 10;
         SpiderStatus = 0;
         TheSpider.GetComponent<Animation>().Play("idle");
         AttackSphere.SetActive(true);
         DetectSphere.SetActive(true);
         AttackPlayer.DealingDamage = 0;
     }
 
 }



 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class AttackPlayer : MonoBehaviour
 {
 
     public GameObject TheEnemy;
     public float EnemySpeed;
     public static int DealingDamage;
     public GameObject DetectSphere;
     public int Damage;
 
     void Update()
     {
         if(LeatherArmor.ArmorBonus >= 5)
         {
             Damage = 1;
         }
         if(LeatherArmor.ArmorBonus < 5)
         {
             Damage = 5 - LeatherArmor.ArmorBonus;
         }
     }
 
     void OnTriggerEnter(Collider other)
     {
         DetectSphere.SetActive(false);
     }
 
     void OnTriggerStay(Collider other)
     {
 
         if (DealingDamage == 0)
         {
    
             EnemySpeed = 0f;
             TheEnemy.GetComponent<Animation>().Play("attack");
             StartCoroutine(HurtPlayer());
         }
     }
 
     void OnTriggerExit(Collider other)
     {
         DetectSphere.SetActive(true);
     }
 
     IEnumerator HurtPlayer()
     {
         DealingDamage = 2;
         yield return new WaitForSeconds(0.5f);
         if (SpiderEnemy.Spider != 6)
             {
                 Health.HealthValue -= Damage;
                 LeatherArmorSkill.LeatherArmorEXP += LeatherArmor.ArmorBonus;
             }
         yield return new WaitForSeconds(0.5f);
         DealingDamage = 0;
     }
 }
Comment
Add comment
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

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

207 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 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

Background Music Error! 1 Answer

How to create a duplicate(Clone) object and participate in the CinemachineTargetGroup as a target with script? 0 Answers

Problem of collision with the zombie (my zombie does not die when on jumps on his head) 0 Answers

How can I make this script to destroy every enemy with this script instead of of only one enemy out of the 50 0 Answers

How can I duplicate a gameObject, its mesh, but *none* of its components? 0 Answers


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