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 /
  • Help Room /
avatar image
0
Question by Nate1576 · Dec 28, 2021 at 02:51 AM · script.beginnerinvokerepeatingdebug.log

Why does Debug.Log continue to execute from Start() and why does InvokeRepeating() not?

While trying to figure out why InvokeRepeating() doesn't execute I noticed the line: Debug.Log("Initial moveSpeed: " + moveSpeed); continuously executes.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class PlatformControl : MonoBehaviour
 {
     [SerializeField] float moveSpeed;
     private Vector3 randomRotation;
     private Rigidbody platformRigidbody;
     private float removePositionZ;
     // Start is called before the first frame update
     void Start()
     {
         moveSpeed = 1500f;
         platformRigidbody = GetComponent<Rigidbody>();
         randomRotation = new Vector3(Random.Range(0f, 15f), Random.Range(-25f, 25f), 0f);
         transform.Rotate(randomRotation);
         removePositionZ = Camera.main.transform.position.z;
         Debug.Log("Initial moveSpeed: " + moveSpeed); // This line is the issue... why?
         // After ten seconds begin to increase moveSpeed every second
         //InvokeRepeating("MoveSpeedControl", 10.0f, 1.0f);
     }
 
     // Update is called once per frame
     void Update()
     {
         
         MovementControl();
     }
 
     void MovementControl() // Controls platform movement
     {
         Vector3 movementVector = new Vector3(0f, 0f, moveSpeed * Time.deltaTime);
         platformRigidbody.velocity = movementVector;
         if(transform.position.z > removePositionZ){ Destroy(gameObject); }
     } 
 
     void MoveSpeedControl()
     {
         Debug.Log("Enter MoveSpeedControl");
         while(moveSpeed < 2000)
         {
             moveSpeed += 1;
             Debug.Log("Current Move Speed: " + moveSpeed);
         }
     }
 }

At first I thought the InvokeRepeating() was somehow interfering (hence why it is commented out) but that isn't the case. I'm hoping,I have been having trouble getting the InvokeRepeating to execute; I use it in another script without issue but this one doesn't seem to cooperate.

I'm hoping someone else can see what I cannot. Thanks for the assistance!

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

Answer by Nate1576 · Jan 03 at 03:18 AM

I determined the reasoning for this; if my understanding of prefabs is correct.

Each instance of the platform prefab brought a new instance of the script. So, because of that, the Debug.Log() message was being displayed with each new instance of the prefab.

Were the instances to stay for the 10 seconds, that part of the code would have been executed as well.

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

219 People are following this question.

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

Related Questions

How can I improve this code? 1 Answer

Im doing a Countdown on Debug. and it works but the numbers repeat. 1 Answer

[Absolute beginner] Play animation on trigger (trigger = several fallen objects) script 1 Answer

HingeJoint motor will not change values? 1 Answer

Jump animation not returning to normal? 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