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 /
avatar image
0
Question by adam_unity566 · Jul 27, 2020 at 03:05 PM · gameobjectintsetactivezombiehealth

Zombie won't die

I have a zombie in my game. It can take damage but it won't die. Here is the script for the zombie.

using UnityEngine;

public class Target : MonoBehaviour { public static int Health = 100; public Animator anim; public GameObject Zombie;

 public void TakeDamage(int amount)
 {
     void Update()
     {
         if (Health <= 0)
         {
             Die();
             Invoke("Gone", 2);
             Zombie.SetActive(false);
             Debug.Log("the zomb died");
         }
         if (Health < 0)
         {
             Die();
             Invoke("Gone", 2);
             Zombie.SetActive(false);
             Debug.Log("the zomb died");
         }
     }

     void Die()
     { 
         GetComponent<Animator>();
         anim.Play("Death"); 
     }
     
     void Gone() 
     {
         Destroy(gameObject);
         Zombie.SetActive(false);
     } 
 }

}

Comment
Add comment · Show 4
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 segy0296 · Jul 27, 2020 at 03:32 PM 0
Share

Have you checked if the health is decreasing? you should do Debug.Log(Health) in the update(). This could be due to health not being reduced properly. Also within the update() you have unecessary conditions, you can delete the if (Health < 0), as it does the same thing as the first condition if (Health <= 0).

avatar image adam_unity566 segy0296 · Jul 27, 2020 at 06:07 PM 1
Share

yes, I know that the health is decreasing. also, I will remove the unnecessary conditions

avatar image Berir · Jul 28, 2020 at 03:10 PM 0
Share

What do you mean by zombie wont die? do you meant script does not reduce health? because I don't see anywhere you actually subtracting any damage!, you should have something like Health = Health - Damage; and then check if health is less or equal zero..... or do you mean it wont play death animation? or that it wont remove zombie from the game?

and why is you Update function inside take damage function? Why do you use Destroy object and Set active.... you cant set inactive something that already has been destroyed

avatar image adam_unity566 Berir · Jul 28, 2020 at 11:13 PM 0
Share

Ok 1. I do not mean it doesn't reduce health (I already have the health reducer in another script) 2. I also do not mean it won't play the death animation 3. I also do not mean that the zombie isn't being destroyed. 4. I don't know why the update function is in the takedamage function I, can change it The problem is that the death function is not being called. All of these things would happen but the if statement (if (Health <= 0) is not triggering.

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by jamesvhyde · Jul 27, 2020 at 05:57 PM

There is a problem in your originally posted code. All your methods ( Update, Die, Gone) are nested inside another method, TakeDamage. The TakeDamage method shouldn't be there. Update and the rest need to be inside the Target class, not inside a method that is inside the class.

Also, this code is suspicious:

 void Die()
      { 
          GetComponent<Animator>();
          anim.Play("Death"); 
      }

You must mean either

 void Die()
      { 
          anim.Play("Death"); 
      }

or

 void Die()
      { 
          GetComponent<Animator>().Play("Death"); 
      }

The first one (and your code) will only work if you have animator set correctly in the Inspector in the editor.

Comment
Add comment · Share
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
0

Answer by rishitsood · Jul 27, 2020 at 05:20 PM

A screen recording would help`

Comment
Add comment · Show 11 · Share
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 adam_unity566 · Jul 27, 2020 at 06:14 PM 0
Share

Here you go

avatar image adam_unity566 · Jul 27, 2020 at 06:15 PM 0
Share

file:///C:/Users/adam/Videos/Captures/Unity%202019.1.0f2%20Personal%20-%20[PREVIEW%20PACKAGES%20IN%20USE]%20-%20Apocalight.unity%20-%20scawy%20zombwi%20gwam%20he%20-%20PC,%20$$anonymous$$ac%20&%20Linux%20Standalone_%20_DX11_%202020-07-27%2014-12-00.mp4

if that doesnt work try this

avatar image Llama_w_2Ls adam_unity566 · Jul 27, 2020 at 06:17 PM 0
Share

Bruh, this is a link to a file on your computer. You cant send the link. You need to convert it to a format available to be shared.

avatar image adam_unity566 Llama_w_2Ls · Jul 27, 2020 at 11:28 PM 0
Share

oops sorry :/ as you can see I'm not very technically smart.

Show more comments

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

210 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 avatar image avatar image avatar image

Related Questions

game object set active on trigger enter? 3 Answers

Problem with PlayerHealth and renderer 1 Answer

activate GameObject dont work 1 Answer

GameObject variable doesn't get filled in 0 Answers

Script is giving error that no MonoBehaviour scripts in file 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