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 walkerion · Jul 24, 2012 at 08:23 AM · methodinvokerepeatingcall

InvokeRepeating can't call method

Ok, i get this error when trying to use InvokeRepeating "Trying to Invoke method: Player.PosionDamage couldn't be called." What's wrong? I checked the reference and couldn't find anything different about their InvokeRepeating example.

 void Update () {
  if (poison == true){
  Invoke("DartPoisonOff", PoisonTime);
  InvokeRepeating ("PosionDamage", 0f, .5f);
     }
         
  void DartPoisonOff (){ 
  poison = false;
  }
  
  void PoisonDamage(){
  health -= PosionDamagePerHalfSecond;
  }
     }
 

 
Comment
Add comment · Show 3
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 Fattie · Jul 24, 2012 at 09:15 AM 0
Share

invokerepeating has a ridiculous known bug where the first paramater cannot be zero. try 0.0001 and see if that helps.

avatar image Fattie · Jul 24, 2012 at 09:16 AM 3
Share

DO NOT use invokerepeating in Update!! heh. it is very likely you want to use it in Start() r in some other function - not in update.

avatar image walkerion · Jul 24, 2012 at 09:27 PM 0
Share

Lol thanks so much. That was 2/3 of my problems with this script. The other was a spelling error >.< I guess I have trouble typing Poison...

3 Replies

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

Answer by Fattie · Jul 24, 2012 at 09:20 AM

look, like this

say you want exciting poison effects to last for THREE seconds, and then end

 function BeginPoisonEffectsNow
    InvokeRepeating("_poisonOneStep", 0.001, 0.5);
    Invoke( "_poisonCleanUp", 3.0 );
 
 function _poisonOneStep
    here, do your animation, health change or whatever
 
 function _poisonCleanUp
     CancelInvoke

that's it - it's that simple.

You see this everywhere constantly in video games. Some video game code is nothing more than zillions of these!

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
3

Answer by Kryptos · Jul 24, 2012 at 01:10 PM

Is is simply a spelling error: your method is called PoisonDamage but you are trying to call PosionDamage.

Anyway the other answers give some other useful hints about repeating actions.

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 walkerion · Jul 24, 2012 at 09:27 PM 0
Share

Thanks :D

avatar image
0

Answer by pheash · Jul 24, 2012 at 09:06 AM

While poison is true it will call an InvokeRepeating on every cycle of the Update! you could use a counter that waits for poison time and then cancels the Invoke repeating. sorry i dont know C but this is what i think it should look like:

 var poisonInstance : float;      //this will hold the time when poison starts invoking. sorry dont know the syntax to declare variables in C.
 void Update(){
 if(poison == true){
   poison = false; // this is now only called once!
   poisonInstance = Time.time;   // we set it to the current time  
   InvokeRepeating("PoisonDamage", 0f, .5f); // this command will call PoisonDamage() every .5 s until told otherwise by canceling it.
  }
  if(Time.time > poisonInstance + PoisonTime && IsInvoking("PoisonDamage")){  // here we check whether the current time is bigger than the time poison was true + PoisonTime (which i assume is holding how long the effect lasts for in seconds) and if we are invoking poison damage we cancel it.
   CancelInvoke("PoisonDamage");
  }
 }

Hope that makes sence. let me know if you have any questions

Comment
Add comment · Show 3 · 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 Fattie · Jul 24, 2012 at 09:18 AM 0
Share

pheash, you simply call CancelInvoke form another "clean up" routine you just invoke.

avatar image pheash · Jul 24, 2012 at 09:56 AM 0
Share

thanks fattie, that looks a lot neater. i am not very experienced in scripting and was looking forward to those sort of simplifications!

avatar image walkerion · Jul 24, 2012 at 09:34 PM 0
Share

Yea, I made another variable to check and see if poison damage is already being dealt. And I have a clean up method that was also invoked. Thanks so much everyone! It's working perfectly now :)

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

7 People are following this question.

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

Related Questions

Why is InvokeRepeating not working in boolean method? 0 Answers

Call method from attached Gameobject 1 Answer

Is there any way to check which method called a certain other method? 1 Answer

Android. Call Method 0 Answers

can't call script variable from another script 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