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
1
Question by Silencerx · Sep 20, 2011 at 06:16 AM · updateinvokerepeating

InvokeRepeating not executing - recently updated unity

Hi, i recently updated unity from about 3.2 to 3.4 and I just started working on a game i had taken a break from. alot of stuff is broken now. anyway one problem i am having is my ship(player) is not firing bullets.

please note: this and all my code worked perfectly fine when i took a break 3 months ago

through the use of monodevelop debugging and debug.log's i have tracked the problem to

 InvokeRepeating("spawnBullet", firstShotDelay, fireRate);

when this function is executed this class is supposed to repeat

 void spawnBullet() {
         Instantiate(bullet,transform.position,transform.rotation);
 }

however through debugging i have concluded that InvokeRepeating is either being executed and not working, or is being skipped over, however through breakpoints i have watched it execute and do nothing.

MY QUESTION: if anyone knows why i am having these problems please help me out. why is InvokeRepeating not working? what did unity update do to my game?

here is the code for spawning a bullet in my game which i am having this problem, i have some comments in please ask any questions if it is confusing:

 using UnityEngine;
 using System.Collections;
 
 public class bulletspawner : MonoBehaviour {
 
     public GameObject bullet;
     public GameObject spreadShotBullet;
     public GameObject rapidFireBullet;
     public float firstShotDelay = 0.02f;
     public float fireRate = 0.2f;
     public float rapidFireRate = 0.1f;
     public bool isSpreadShot = false;
     
     private bool spreadShotEnabled = false;
     private bool rapidFireEnabled = false;
     private bool needsUpdate = false;
     
     public static bool rapidFire = false;
     public static bool spreadShot = false;
     
     //spawns a bullet at the ships position and rotation
     void spawnBullet() {
         Instantiate(bullet,transform.position,transform.rotation);
     }
 
     void spawnSpreadBullet() {
         Instantiate(spreadShotBullet,transform.position,transform.rotation);
     }
     
     void spawnRapidFireBullet() {
         Instantiate(rapidFireBullet,transform.position,transform.rotation);
     }
 
     void spawnTheBullets ()
     {
         //this repeats spawning the bullet at a firerate in seconds
         if (!isSpreadShot && !spreadShotEnabled && !rapidFireEnabled)
         {
             InvokeRepeating("spawnBullet", firstShotDelay, fireRate);
         }
         else
         {
             //Debug.Log("ss:" + spreadShotEnabled + " rf:" + rapidFireEnabled);
             if (spreadShotEnabled && !rapidFireEnabled)
             {
                 InvokeRepeating("spawnSpreadBullet", firstShotDelay, fireRate);
             }
             else
             {
                 CancelInvoke("spawnSpreadBullet");
             }
 
             if (rapidFireEnabled && !isSpreadShot && !spreadShotEnabled)
             {
                 InvokeRepeating("spawnRapidFireBullet", firstShotDelay, rapidFireRate);
             }
             else
             {
                 CancelInvoke("spawnRapidFireBullet");
             }
         }
     }
 
     void stopSpawning()
     {
         CancelInvoke("spawnBullet");
         CancelInvoke("spawnSpreadBullet");
         CancelInvoke("spawnRapidFireBullet");
     }
     
     void Awake (){
         spreadShotEnabled = false;
         rapidFireEnabled = false;
 
         rapidFire = false;
         spreadShot = false;
 
         if (globalController.overide)
         {
             fireRate = globalController.gnormalFireRate;
             rapidFireRate = globalController.grapidFireRate;
         }        
     }
     
     // Update is called once per frame
     void Update () {
         if (rapidFireEnabled != rapidFire || spreadShotEnabled != spreadShot)
         {
             stopSpawning();
             needsUpdate = true;
         }
 
         rapidFireEnabled = rapidFire;
         spreadShotEnabled = spreadShot;
 
         if (needsUpdate && Input.GetButton("Fire1"))
         {
             needsUpdate = false;
             spawnTheBullets();
             
         }
         //spreadShotEnabled = shipcontrols.globeSpreadShotEnabled;
         //Debug.Log(spreadShotEnabled);
             
             
         //the frame the fire1 input is pressed it starts a repeating function
         //note: that if this is not done multiple instances of a bullet repeatedly spawning will occur.
         // as the repeating will be invoked every frame.
         if(Input.GetButtonDown("Fire1")){
             spawnTheBullets();
         }
         //the frame the button is released the repeated spawning of the bullet is stopped
         if(Input.GetButtonUp("Fire1")){
             stopSpawning();
         }
     }
 }
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 Silencerx · Sep 23, 2011 at 12:47 PM

well seen as how no one knows the answer i may as well just tell you.

my time scale inadvertently got set to 0, stopping time, during the update process, so the code called on update was never happening, only on press events.

thats some super homosexual feces!!!

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

2 People are following this question.

avatar image avatar image

Related Questions

Convert InvokeRepeating into the Update method... 1 Answer

Using InvokeRepeating in the Update method? 2 Answers

Prefab Instantiation 1 Answer

InvokeRepeating OR Update OR FIxedUpdate? 2 Answers

How to slow down a function call in C# unity 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