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 zillion · Jul 11, 2012 at 11:28 AM · javascriptraycastattackwaitseconds

Take damage after seconds

I have two functions that work together in order to take damage off my first person controller. One has alot of other stuff (such as turn to target), and the main part being:

 if(animation["AttackingPlayer"].time >= 0.6
 {
 RayCastFunction();
 }

And then the RayCastFunction will create a raycast coming from the enemy, and hitting the first person controller. Although, the function seems to play a ton of times, and then the first person controller looses all of his life after 0.6 seconds. I can see it going down from 100, so he is not loosing it all at once. Is there a way I can play the RayCastFunction once per animation loop? Because I would only like to take the damage off the player once per attacking animation. Yet the animation must still wait for 0.6 seconds to take the damage since I do not want damage being taken off if the animation has only played for 0.1 seconds and the character decides to run away... Very unrealistic. Should be a VERY SIMPLE fix, although I am quite new to Unity. Thank you for your help!

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

3 Replies

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

Answer by asafsitner · Jul 11, 2012 at 11:33 AM

You can use animation events

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 The_Magical_Kiwi · Jul 11, 2012 at 11:37 AM

If you declare a bool at the top of your script, you can then use the bool as a switch.

An example will probably be clearer.

 //Pseudo code
 bool damageDone = false;
 
 if(animation["AttackingPlayer"].time >= 0.6){
    if(!damageDone){
       RayCastFunction();
       damageDone = true;
     }
 }

Once your animation has finished, set damageDone back to false and you start again.

Comment
Add comment · Show 1 · 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 The_Magical_Kiwi · Jul 11, 2012 at 11:38 AM 0
Share

...or you could take @asafsitner 's advice, which is a much better solution that I had forgotten about... ^^

avatar image
0

Answer by zillion · Jul 11, 2012 at 01:25 PM

I believe that the animations event method will not work for this since my character starts in an idle animation, and the attacking animation is only called when the enemy is in close proximity of my first person controller. Unless I'm not using the animations event correctly? It's only letting me do it for the starting animation of the enemy...

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

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Need help with simple RayCast Attack script 1 Answer

GetComponent() problems 2 Answers

Problem with yield waitForSeconds in for loop 0 Answers

How to Less Than or Equal to with a Raycast? 1 Answer

Why UI layer is being ignored by the raycast? 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