0

I have a problem with a game I am programming in unity. This specificaly occured when i added the script given below. the error message says that no monobehaviorscripts in the file, or their names do not match the file name. This script is meant to spawn the eniemies in the game.

I have already tried changing the class name, file name and copy the one into the other. but this does not seem to help.

screenshot unity of error message and code enter image description here

i just edited my code and it does not seem to be solved.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class wavesystem : MonoBehaviour
{
    public int enimicount;
    public int[] enimi = { 1 };
    public int wave = 1;
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        if (enimicount = 0) 
        {
            int threat = 0;
            for (threat < wavesystem.wave) 
            {
            int name = Random.Range(0, wavesystem.enimi.Length);
            int enimitreat = wavesystem.enimi[name];
            if (threat + enimitreat <= wave) 
                {   
                float xpos = Random.Range(0, 2);
                Instantiate("enimie" + name, (xpos, 1));
                wavesystem.enimicount = wavesystem.enimicount + 1;
                threat = threat + enimitreat;
                }

            }
            wavesystem.wave = wavesystem.wave + 1;
        }

    }
}

Beas
  • 9
  • 1
  • 1
    Are you sure the file name is equal to the name shown in Unity? – IndieGameDev Dec 01 '20 at 10:46
  • Have you tried creating a new file but only copying the code inside of the class? So without `public class wavesystem` and such, in case there is a spelling mistake somewhere – funie200 Dec 01 '20 at 11:00
  • 3
    Compiler cant compile this script because of errors in Update(). Try to solve errors first – selezen88 Dec 01 '20 at 11:11
  • Are you sure your script file has "cs" extension? – selezen88 Dec 01 '20 at 11:13
  • Probably a typo in `random.Range` .. should be `Random.Range`, same for `random range` .. also `instantiate` should be `Instantiate` .. etc fix your compiler errors first – derHugo Dec 01 '20 at 19:27
  • thanks @derhugo, helped a lot, but i think i can not find all errors i already updated the code with things i noticed after reading your comment. – Beas Dec 01 '20 at 19:55
  • Well.you should rather read the console in Unity and fix the errors one by one ;) – derHugo Dec 01 '20 at 20:21

2 Answers2

-1

you need the exact same name in the unity editor for the script as well as in the code editor (I suppose visual studio). the name is Case Sensitive and needs to be correctly spelled in each part. check the name and the location of the file and place them so they are easily found by you.

for example: Name in unity: WaveSystem_LoL

//Name in C# code:

   public class WaveSystem_LoL : MonoBehavior

if they do not match the error will appear so double and even triple check!

Jadon Wolfgang
  • 180
  • 1
  • 12
-1

Seems like your file name is different than class name. Your file name of cs file should be wavesystem.cs