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 /
avatar image
0
Question by Silentones · Mar 28, 2019 at 06:58 AM · animationplayerenemyhealthbarhealth-deduction

How come my Player, Enemy, Animation & HealthSlider won't correspond to one another?

I am lost... everything makes sense when I read it, but I am not sure why it is not getting the damage from the enemy and decreasing my player's health bar. My hurt animation is going crazy too. Its triggered right at the start. When I set the trigger on "Any status" So does that mean it's triggering because i have an idle animation?

3. FoxFight Health&Damage(GitHub)

YouTube: Visual Glitch

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by IronBytes · Mar 28, 2019 at 08:47 AM

In OpossumAttack.cs you are fetching the PlayerHealth on the Opossum Game Object in line 19. Use "Target.GetComponent()" instead to fetch it from the player Game Object.

Also you are calling TakenDamage in the Update function from your PlayerHealth script, so the player takes damage every frame no matter if there is an enemy nearby. You should remove it from the Update loop. (Player Health line 31)

Let me know how it goes as it may not fix all of the problems. Cheers.

Comment
Add comment · Show 6 · 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 Silentones · Mar 29, 2019 at 04:33 AM 0
Share

That worked. Can you help me with my hurt and screen damage Flash Functions?

avatar image IronBytes · Mar 29, 2019 at 07:40 AM 0
Share

I do not have much experience with animations, so I'd need to fork your GitHub project and play around with it a bit. I won't be home over the weekend though so you'll have to wait until next week. $$anonymous$$aybe someone else can jump in in the meanwhile ;)

avatar image Silentones IronBytes · Mar 30, 2019 at 01:20 AM 0
Share

That's fine I'll try to figure it out and then come back here if it's still messed up.

avatar image IronBytes · Apr 01, 2019 at 08:50 AM 0
Share

Good $$anonymous$$orning, so I checked out your project today and the problem with your animation is that the hurting animation is never turned off. It is triggered when the player takes damage and then goes on forever because the boolean "hurting" trigger is never set to false afterwards.

So I made a quick function that resets the animation after a short amount of time, which is called in TakeDmg:

     public void TakenDmg(int amount)
     {
         damage = true;
 
         currentHealth -= amount;
         healthSlider.value = currentHealth;
 
         anim.SetBool("Hurting", true);
         StartCoroutine(ResetHurtAnimationInSeconds(1));   
     }
 
     public IEnumerator ResetHurtAnimationInSeconds(float timeUntilReset)
     {
         yield return new WaitForSeconds(timeUntilReset);
         anim.SetBool("Hurting", false);
     }

avatar image Silentones IronBytes · Apr 02, 2019 at 04:01 AM 0
Share

I tried this over the weekend I think its the same idea, but my code did not work. Do I need to make a new function?

  public void TakenDmg(int amount)
     {
         damage = true;
     
         currentHealth -= amount;
         healthSlider.value = currentHealth;
     
         anim.SetBool("Hurting", true);
     
         if (!damage)
         {
             anim.SetBool("Hurting", false);
         }
     
         //if (currentHealth <= 0 ) {
         //    Death();
         //}
     
     }
avatar image IronBytes · Apr 02, 2019 at 08:27 AM 0
Share

Code is always executed from top to bottom. So in your code when TakenDmg is called 'damage' is first set to 'true' and then you check with if(!damage) whether it is 'false'. This if-statement will never become true so the code inside it is never executed. If you want to trigger "Hurting" manually, then you need to place the code outside the TakenDmg function and call it somewhere else.

You had the right idea though, setting "Hurting" to false.

If you have some time I would suggest you to do a beginner coding tutorial. Space Shooter and Survival Shooter are good options. When you do that, take some time to understand why the code works and how it operates. I think it can help you a lot moving forward with your project.

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

124 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

Related Questions

How To Make Enemy Chase You? 1 Answer

Why enemy animation messes up the player ? 0 Answers

Enemies push player a ridiculous amount. 1 Answer

How to make this GUITexture work. 1 Answer

Animated Object phases through Player 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