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 Aractos · May 28, 2012 at 04:13 PM · functionclassinvokerepeating

InvokeRepeating couldn't be called for a function inside an instanced object

Hi, i'm working actualy on a Atb gauge for multiple character and i got some trouble with the InvokeRepeating method who i use to fill up my gauge, there is a template of the whole script (ask me if more line of the script are needed), i've tryed multiple way to make it work too.

Way I want the script to work:

In BattleSystem script :

 var characterPicture : Texture;
 var character : BaseStats;
 
 Start()
 {
 // create the new character & start invoke repeating
 character = new BaseStats("My character", characterPicture, 9, 9, 9, 9, 10000000);
 character.AtbConfig(); //configure speed of the atb gauge
 character.atbGaugeFull = false;
 InvokeRepeating("character.AtbGaugeOn",0,character.atbSpeedTime);
 }
 

In CharacterStats script :

 BaseStats class
 {
 
 // ...stats for character & function used by it
 
 function AtbGaugeOn()
 {
     if(atbGaugeFull == false)
     {
         atbCurrentTime += atbSpeedTime;
         if(atbCurrentTime >= baseAtbFillTime)
         {
             atbGaugeFull = true;
             atbCurrentTime = 0;
         }
     }
 }
 
 // ...another stats & constructor
 }

Error = Trying to invoke method: BattleSystem.character.AtbGaugeOn couldn't be called.

Way it work but who i won't him to work:

In BattleSystem script :

 var characterPicture : Texture;
 var character : BaseStats;
 
 Start()
 {
 // create the new character & start invoke repeating
 character = new BaseStats("My character", characterPicture, 9, 9, 9, 9, 10000000);
 character.AtbConfig(); //configure speed of the atb gauge
 character.atbGaugeFull = false;
 InvokeRepeating("AtbGaugeOn",0,character.atbSpeedTime);
 }

 function AtbGaugeOn()
 {
     if(character.atbGaugeFull == false)
     {
         character.atbCurrentTime += character.atbSpeedTime;
         if(character.atbCurrentTime >= character.baseAtbFillTime)
         {
             character.atbGaugeFull = true;
             character.atbCurrentTime = 0;
         }
     }
 }

Actualy i want 1 atb gauge for ech character & npc in the battle who fill up over time depend on the speed value of the actual character or npc. on this script as i got only one character it can work on both way but soon i will have 6 character i don't think the second way will work properly. I've tryed to fill the gauge with a while loop but unity crash when used :

 function AtbGaugeOn()
 {
     while(atbGaugeFull == false)
     {
         atbCurrentTime += (atbSpeedTime*Time.deltaTime);
         if(atbCurrentTime >= baseAtbFillTime)
         {
             atbGaugeFull = true;
             atbCurrentTime = 0;
         }
     }
 }

Thx in advance for any help.

Ps: Please apologize my poor english i'm not a native user of it.

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
1
Best Answer

Answer by whydoidoit · May 28, 2012 at 04:17 PM

You can't use InvokeRepeating on a method which isn't on a MonoBehaviour - so you wil have to use a coroutine:

 function AtbGaugeOn() : IEnumerator
 {
     var lastTime = Time.time;
     while(atbGaugeFull == false)
     {
        atbCurrentTime += (atbSpeedTime*(Time.time - lastTime));
        lastTime = Time.time;
        if(atbCurrentTime >= baseAtbFillTime)
        {
          atbGaugeFull = true;
          atbCurrentTime = 0;
        }
         yield WaitForSeconds(atbSpeedTime/* Put your delay here */);
     }
 }

Then do

 StartCoroutine(character.AtbGaugeOn());

The way it's coded may not be right though, it will only do this once until the gauge is full at the moment

Comment
Add comment · Show 8 · 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 flamy · May 28, 2012 at 04:19 PM 1
Share

touche i was typing it :P you are so fast ;)

avatar image whydoidoit · May 28, 2012 at 04:27 PM 0
Share

I'd better give up soon and do some real work !!

avatar image Aractos · May 28, 2012 at 04:31 PM 0
Share

Thx for the answer but i got a new error now when i use the code u give : Code = character.InvokeRepeating("AtbGaugeOn",0,character.atbSpeedTime); Error = $$anonymous$$issing$$anonymous$$ethodExeption: $$anonymous$$ethod not found : 'BaseStats.InvokeRepeating'

avatar image whydoidoit · May 28, 2012 at 04:37 PM 0
Share

Sorry, my mistake - it isn't a damn $$anonymous$$onoBehaviour is it!

That's what comes of answering too fast I guess.

avatar image whydoidoit · May 28, 2012 at 04:45 PM 0
Share

Updated the answer

Show more comments

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I call a new class function with InvokeRepeating ? 1 Answer

Loop a function, once per second, X number of times 1 Answer

Invoke.Repeating doesn't really "care" about repeat time? 1 Answer

function isnt working in the class 0 Answers

Inherited class, trying to overwrite variable. 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