I'm trying to do a project for my coding class, and I need help. I've been at this for almost an hour and can't figure out why it won't work. I am working with unity and it's Visual Studio Code. What I want to happen is whenever I enable my cube, it says Creating enemy number: and then it counts to five.
My current errors are these:
My current code is this:
If you could please lead me in the right direction it would be greatly appreciated. Thank you for reading! :3
My current errors are these:
C#:
[10:26:24] Assets\Scripts\Enemies.cs(16,13): error CS0128: A local variable or function named 'numEnemies is already defined in this scope
[10:26:24] Assets\Scripts\Enemies.cs(18,19): error CS0136: A local or parameter named 'numEnemies' cannot be declared in this scope because that name is used in an enclosing local scope to define a local parameter
[10:26:24] Assets\Scripts\Enemies.cs(16,13): warning CS0219: The variable 'numEnemies is assigned but it's value is never used
My current code is this:
C#:
{
// for ( ; ; ) {}
void OnEnable ()
{
int numEnemies = 5;
Debug.Log("Creating enemy number: " + numEnemies);
for ( int numEnemies = 0; numEnemies < 5; numEnemies++ )
{
Debug.Log ( numEnemies );
}
}
}
Last edited by a moderator: