Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Earl_Wade · Aug 26, 2016 at 05:09 PM · colliderhealth

Having a small problem with the player getting a "free hit" before they die

I built a 2D shooter and everything works as I want it to, The players shields go down to zero after being hit, and then the health gets taken. when the player gets down to zero health, they seem to have an extra hit, where they have 0 health and 0 shields, but still haven't died. Here is the portion of my script that deals with taking damage

//if it is a enemy entity

     else if (other.tag == "EnemyShip" || other.tag == "EnemyProjectile") 
     {

         //shakes the camera
         CameraShake.shake = true;

         //sets the upgraded weapon to be downgraded
         WeaponDowngrade();

         //runs a check to see if the player has shields
         if (curShields > 0)
         {
             //plays the power up sound effect
             AudioSource.PlayClipAtPoint(ShieldHit, transform.position);         
                                                                                 
             //takes away some of the player shields                             
             ModShields(-5);
             
         }
         //if there is no shields and the player still has health
         else if (curHealth >  0)
         {
             //plays the power up sound effect
             AudioSource.PlayClipAtPoint(ShipHitnoshield, transform.position);

             //take away some of the player health
             ModHealth(-1);
           
         }
         //if the player has no health left
         else if(curHealth == 0)
         {
             //plays the explosion audio
             AudioSource.PlayClipAtPoint(BlowUp, transform.position);

             //take away a life
             ModLives(-1);

             //reset the players health and shields
             ResetPlayer();                            
         }        
     } 

Is there something simple that I seem to be missing?

Comment
Add comment · Show 2
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 Dream_in_code · Aug 26, 2016 at 05:28 PM 0
Share

if HP = 0 then why will it take -1 life again?

avatar image Earl_Wade Dream_in_code · Aug 27, 2016 at 12:58 PM 0
Share

How it is set up, is the player ship takes damage on his shields before health damage. The shields work, counting down from 100 to zero when taking damage. Then the health starts counting down from there. I should probably set the curHealth if its == to one and takes damage, then they lose a life.

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

75 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

Related Questions

Health bar/damage script not working. Please help. 0 Answers

Tool Durability if Hit any Collider 1 Answer

My health potion worked and now it doesn't. 1 Answer

Check if position is inside a collider 5 Answers

Spawning with trigger 2 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