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();
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!
↧