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

Can't add script

Discussion in 'Scripting' started by Void5703, Aug 28, 2021.

  1. Void5703

    Void5703

    Joined:
    Aug 28, 2021
    Posts:
    9
    Because script class not found. I don't know what I did wrong, if anything. I can post the code if someone is willing to help. I was making a basic controller as a test run and now it just won't work.
     
  2. diXime

    diXime

    Joined:
    Oct 2, 2018
    Posts:
    162
    Hello,
    Usually, this issue comes from the fact that your script
    • Has a different name that its file (
    public class MyClass
    must be in a file called
    MyClass.cs

    • Your class doesn't inherent from MonoBehaviour (
    public class MyClass : MonoBehaviour
    )

    If the first two reasons don't apply, you can copy/paste your code here using the code tags (the button right next to "Code" in the bar on top of the text area or using
    [code=CSharp][/code]
    ).
     
    PraetorBlue likes this.
  3. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    In addition to this, make sure you don't have any compile errors in your console. All compile errors will have to be fixed before you can attach the script.