Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

I keep getting the 'the script don't inherit a ntive class that can manage a script'

Discussion in 'Scripting' started by maxandgrandad, Jan 22, 2021.

  1. maxandgrandad

    maxandgrandad

    Joined:
    Jan 21, 2021
    Posts:
    3
    I keep getting the 'the script don't inherit a ntive class that can manage a script' when I drag my script to an object
    The code is here
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class LevelController : MonoBehaviour
    {
    Monster[] monsters;

    [SerializeField] string nextLevelName;

    void OnEnable()
    {
    monsters = FindObjectsOfType<Monster>();
    }

    // Update is called once per frame
    void Update()
    {
    if (MonstersAreAllDead())
    GoToNextLevel();
    }

    void GoToNextLevel()
    {
    Debug.Log("Go to Level " + nextLevelName);
    }

    bool MonstersAreAllDead()
    {
    foreach (var monster in monsters)
    {
    if (monster.gameObject.activeSelf)
    return false;
    }
    return true;
    }
    }
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,725
    What's the name of this file?
    Do you have any other errors in your console?
     
  3. maxandgrandad

    maxandgrandad

    Joined:
    Jan 21, 2021
    Posts:
    3
    I have fixed all other errors and the name of the file is Level Controller.cs
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,797
    If the filename has a space, that's your problem. It must match 100% in spelling and capitalization when it is a MonoBehaviour.
     
    Joe-Censored likes this.
  5. maxandgrandad

    maxandgrandad

    Joined:
    Jan 21, 2021
    Posts:
    3
    It works
    Thanks
     
    Kurt-Dekker likes this.