• 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 $$anonymous$$m 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 t$$anonymous$$s script as i got only one character it can work on both way but soon i will have 6 character i don't t$$anonymous$$nk the second way will work properly. I've tryed to fill the gauge with a w$$anonymous$$le loop but unity crash when used :

 function AtbGaugeOn()
 {
     w$$anonymous$$le(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 w$$anonymous$$ch isn't on a MonoBehaviour - so you wil have to use a coroutine:

 function AtbGaugeOn() : IEnumerator
 {
     var lastTime = Time.time;
     w$$anonymous$$le(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 t$$anonymous$$s 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
avatar image whydoidoit · May 28, 2012 at 04:27 PM 0
Share
avatar image Aractos · May 28, 2012 at 04:31 PM 0
Share
avatar image whydoidoit · May 28, 2012 at 04:37 PM 0
Share
avatar image whydoidoit · May 28, 2012 at 04:45 PM 0
Share
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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

Why is InvokeRepeating not working in boolean method? 0 Answers

Unity C# Start function without extending Mono 2 Answers

Return a custom class from function 1 Answer

using functions as classes 1 Answer

c# passing classes through functions 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