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. Dismiss Notice

The script don't inherit a native class that can manage a script

Discussion in 'Editor & General Support' started by DmE0, Feb 15, 2021.

  1. DmE0

    DmE0

    Joined:
    Feb 14, 2021
    Posts:
    6
    Hi I ran into an error today - "The script don't inherit a native class that can manage a script". It occurs when a script is placed on an object. I looked for possible solutions on the internet, but it didn't help. Hope someone can help. Below I will send the script itself


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

    public class Main1 : MonoBehaviour
    {
    // --
    public Transform ShopPan;
    public Text MoneyText;
    public int Money;
    public int MoneyUp = 1;
    private bool Check = true;

    // --
    void Update()
    {
    MoneyText.text = Money.ToString();
    }
    // --
    public void OnClickButton()
    {
    Money += MoneyUp;
    }
    // --
    public void OnClickShopButton()
    {
    if (Check == true)
    {
    ShopPan.gameObject.SetActive(true);
    Check = false;
    }
    }
    // --
    public void OnClickBuy()
    {
    if (Money >= 100)
    {
    Money *= 2;
    Money -= 100;
    }
    }
    }
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    This always happens to me if I create a script and try to drag it onto an object before Unity has a chance to compile it for the first time.

    Has there been a successful compilation between when you created this Script and when you tried to attach it to the object? Do you have any compile errors in your console?
     
  3. DmE0

    DmE0

    Joined:
    Feb 14, 2021
    Posts:
    6
    I have already fixed this error, you just had to close all active programs and processes (including unity), and then open Unity and everything will work stably.
     
  4. LegitACarWithAGun

    LegitACarWithAGun

    Joined:
    Mar 16, 2021
    Posts:
    1
    If anyone else finds this, check if changing the class name to Transform___ works, ie:
    public class TransformMain1 : MonoBehaviour
     
  5. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    The class name just needs to match file name. "public class Main1" would be in Main1.cs
     
  6. AFlamel

    AFlamel

    Joined:
    May 20, 2021
    Posts:
    15
    If following the Unity naming conventions and still getting this error then try restarting Unity and all files linked to Unity. If that doesn't work then try using different names until one works. That's what I've been doing.

    The image below is an example of a C# file that was made automatically but gives back that prompt.

    In that case Unity is just saying no because a different script is giving back an error. So it wont let me attach a new script until I fix any errors.

    You can check the console for any errors, and the errors do not have to be related to the object you are attaching to. Any error will upset Unity and it will make you fix it before you go about your day.
     
    Last edited: Aug 1, 2021
  7. AFlamel

    AFlamel

    Joined:
    May 20, 2021
    Posts:
    15