I have a slider in the pause menu which will have a min value of 1 and max of 5.
When I change it, the InvokeRepeating
function maintains the same speed, but Debug.Log shows current slider value.
How can I change the InvokeRepeating
rate?
Player.m1 is a float; when I give 5f or something like that to InvokeRepeating
it works fine.
using UnityEngine;
public class Gen1 : MonoBehaviour
{
public GameObject rocks;
int scr = 0;
public int m=0;
float n11=Player.m1;
float sp;
// Use this for initialization
void Start()
{
//if (Player.m1 == 5 || Player.m1==4) {
InvokeRepeating ("CreateObstacle", Player.m1,5f);//Here speed handels
//} else {
//InvokeRepeating ("CreateObstacle", 4f, 5f);//Here speed handels
//}
Debug.Log ("current speed is afad"+Player.m1);
}
void Update()
{
//InvokeRepeating ("CreateObstacle", 4f, Player.m1); //Here speed handels
//Debug.Log ("current speed is afad"+Player.m1);
}
void OnGui()
{
GUI.color = Color.black;
GUILayout.Label ("Score is" + scr.ToString ());
}
void CreateObstacle()
{
Instantiate(rocks);
Player.score += 1;
Debug.Log ("current speed is "+sp);
}
void OnBecameInvisible() {
// Destroy the bullet
Destroy(this.rocks);
}
}
```