Search Unity

No MonoBheaviour scripts in the file

Discussion in 'Scripting' started by aliiiiiiceee, Aug 18, 2020.

  1. aliiiiiiceee

    aliiiiiiceee

    Joined:
    Aug 18, 2020
    Posts:
    1
    I know this has been asked before, but using all of the solutions I've found on this forum haven't helped.

    I'm very new to Unity, and just started following along with the Ruby 2D game tutorial. I have followed the instructions very precisely, and created the first script. Code is below

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class RubyController : MonoBehaviour
    6. {
    7.     // Start is called before the first frame update
    8.     void Start()
    9.     {
    10.        
    11.     }
    12.  
    13.     // Update is called once per frame
    14.     void Update()
    15.     {
    16.         Vector2 position = transform.position;
    17.         position.x = position.x + 0.1f;
    18.         transform.position = position;
    19.     }
    20. }
    21.  
    The name of the script is
    RubyController.cs
    , so the name is correct.

    This is what appears when I try to drag the file to the sprite (link to image: https://ibb.co/nPqL7xP, image also attached as a file). Basically a pop up that says can't add script, and in the inspector it says that there are no MonoBehaviour scripts in the file.

    Please let me know what to do, this is driving me crazy. I am using Unity 2019.4.8f1 on a mac, and Visual Studio for mac. VS is not giving me any compile errors.
     

    Attached Files:

  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    Look at the bottom of your Unity screen. See that red message? There are compile errors in Unity. VS errors don't matter, only Unity errors. Check the console window in Unity to see them all.

    That error also looks like it's from a builtin Unity library (collab). I suggest deleting your Library folder and allowing Unity to regenerate it as a first step.