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

Tofumaks

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.

Yong Shun

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);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related