Adding speed to the rotation every second

What I want to do is to make a script that will change the speed of a object every second, making it spin faster and faster (every second)

Here is the code that doesen’t work :frowning:

using UnityEngine;
using System.Collections;

public class moveFast : MonoBehaviour {
        int p = 2;
        int r = 1;
        
    void Start() {         
         InvokeRepeating("Add", 1.0, 1.0);
         function Add() {
           p += r;
    }
    }
    
    void Update()
    {    
        transform.Rotate(0, 0, p);
    }

    }
}

How do I solve this problem, also I’m using 2D not 3D!
The object is a ball, the error is :

Assets/moveFast.cs(10,21): error CS1525: Unexpected symbol `(', expecting `,', `;', or `='

InvokeRepeating does not accept un named functions neither lambda.
Try doing this :

private IEnumerator IncreaseSpeed()
    {
        p += r;
        yield return new WaitForSeconds(1f);

        StartCoroutine(IncreaseSpeed());
    }

and add :

private void OnDisable()
    {
        this.StopAllCoroutines();
    }

to make sure that this loop stops when this script is disabled.