My Monobehaviour Script doesn't get detected
Hey I've got this neat little script for handling the spawning of some game objects. It works perfectly fine in the original project, but after I transfered it into a new project I suddenly had this error:
No MonoBehavior scripts in the file, or their names do not match the file name.
Does anyone know where this error is coming from? Because I can't use the script this way.
Yes the class name and the file name do match.
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PrefabManager : MonoBehaviour
{
ObjectPooler objectPooler;
public GameManager gm;
int rnd = 0;
float difficulty = 1.5f;
bool diffhelp = true;
int duplicate;
private void Start()
{
objectPooler = ObjectPooler.Instance;
duplicate = rnd;
}
private void Update()
{
bool hardcore = gm.hardcore;
switch (gm.score)
{
case 150:
difficulty = 1.25f;
break;
case 300:
difficulty = 1f;
break;
case 450:
difficulty = 0.9f;
break;
case 600:
difficulty = 0.8f;
break;
case 750:
difficulty = 0.7f;
break;
case 900:
difficulty = 0.6f;
break;
}
if (diffhelp)
{
if (hardcore == false)
{
Invoke("spawn", difficulty);
diffhelp = false;
}
else
{
Invoke("spawn", 0.6f);
diffhelp = false;
}
}
}
private void spawn()
{
while (duplicate == rnd)
{
rnd = Random.Range(0, 7);
}
duplicate = rnd;
diffhelp = true;
objectPooler.SpawnFromPool(rnd.ToString(), new Vector3(0,1,100), Quaternion.identity);
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613033700im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Why does unity not see monobehaviour? 2 Answers
Should I inherit from Monobehaviour if the use of my C# script is only to hold script references? 2 Answers
Why does unity not see monobehaviour? 1 Answer
AddComponent fails when passing in type, works when passing in name 0 Answers
Multiple PowerUps (One ItemBox) 0 Answers