Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I fix the error: "error CS1656: Cannot assign to 'InvokeRepeating' because it is a 'method group'"?

I’m a beginner currently trying to make a game on unity. Right now I’m trying to create an enemy spawners code using the tutorial: https://youtu.be/q1gAtOWTs-o

The thing is, it uses this method called "Invoke Repeating" which brings up the error stated in my title question. Is there any fix I can do to solve the error? Below is my code:

public Transform[] spawnPoints;
public GameObject[] enemies;
int randomSpawnPoint, randomEnemy;
public static bool spawnAllowed;

// Start is called before the first frame update
void Start()
{
    spawnAllowed = true;
    InvokeRepeating = ("SpawnAnEnemy", 0f, 1f);
}

void SpawnAnEnemy()
{
    if(spawnAllowed)
    {
        randomSpawnPoint = Random.Range(0, spawnPoints.Length);
        randomEnemy = Random.Range(0, enemies.Length);
        Instantiate(enemies[randomEnemy], spawnPoints[randomSpawnPoint].position, Quaternion.identity);
    }
}

There are no other errors present and I only changed some variable names (like I used "enemies" instead of "monsters") so I am unsure what the issue is.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

InvokeRepeating is a method. You have to call the method as below:

InvokeRepeating("SpawnAnEnemy", 0f, 1f);

What you did as the attached code is assigning a Tuple value to it which is incorrect.

InvokeRepeating = ("SpawnAnEnemy", 0f, 1f);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading