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 TensivePlot8833 · Jun 25, 2021 at 12:03 AM · damagezombie

I want to make a zombie fps game and the zombie isn't taking damage

I got Unity one day ago and I started to use it today. I wanted to make a zombie fps game as my first game. I need the zombie to walk towards me, deal damage, and take damage. I got all the animation and health bar working, but the zombie isn't taking damage. I tried adding a hitbox object with a collider and a damage script but it isn't working. I know my weapons' are working because I added in another enemy and it was taking damage.

Can anyone help?

My zombie script is below.

 void Start()
 {
     pathfinder = GetComponent<NavMeshAgent>();
     target = GameObject.Find("Player").transform;
 }
 void Update()
 {
     pathfinder.SetDestination(target.position);
 }

My damage script is below.

     [Range(0, 1)] [Tooltip("Multiplier to apply to self damage")]
     public float SensibilityToSelfdamage = 0.5f;

     public Health Health { get; private set; }

     void Awake()
     {
         // find the health component either at the same level, or higher in the hierarchy
         Health = GetComponent<Health>();
         if (!Health)
         {
             Health = GetComponentInParent<Health>();
         }
     }

     public void InflictDamage(float damage, bool isExplosionDamage, GameObject damageSource)
     {
         if (Health)
         {
             var totalDamage = damage;

             // skip the crit multiplier if it's from an explosion
             if (!isExplosionDamage)
             {
                 totalDamage *= DamageMultiplier;
             }

             // potentially reduce damages if inflicted by self
             if (Health.gameObject == damageSource)
             {
                 totalDamage *= SensibilityToSelfdamage;
             }

             // apply the damages
             Health.TakeDamage(totalDamage, damageSource);
         }
     }
 }

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 logicandchaos · Jun 25, 2021 at 05:50 PM 0
Share

Does zombie have a health component? In InflictDamage() at top put Debug.Log(Health); Also not sure how it is working but you named your instance the same as your class.. Health Health; should be Health health; Also can you show the Health script? and maybe your inspector of how your enemies are setup.

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

121 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

Related Questions

Need zombie to inflict damage 0 Answers

Damage trigger? 1 Answer

regenerating health 3 Answers

How to make zombie inflict damage 1 Answer

Attack Script problem please help 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