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

New user : No Monobehaviour scripts in the file ....

Discussion in 'Scripting' started by navaljosh, Aug 7, 2015.

  1. navaljosh

    navaljosh

    Joined:
    Aug 4, 2015
    Posts:
    8
    Hi,
    I just started using unity today, was trying to learn from the below tutorial
    http://anwell.me/articles/unity3d-flappy-bird/

    Got stuck in adding a .cs script as component to my player.
    When i click on .cs script it shows issues with Mono behaviour.
    Ans when i click on my player , the script component shows that u need to fix some errors and script is not loaded.

    Let me know what i can do to fix it.
    I do not see any errors in my script.
     
  2. Lorinthio

    Lorinthio

    Joined:
    Aug 7, 2015
    Posts:
    39
    Could you screen shot or share the issues that are being shown with Mono Behaviour? Also, if you want to insert the code(assuming you're copying/following the tutorial), I can glance over it as I wait for some responses on my post =)
     
  3. navaljosh

    navaljosh

    Joined:
    Aug 4, 2015
    Posts:
    8
    Thanks for the reply, really appreciated.

    Here is the snip[pet, let me know if u need anything else
     

    Attached Files:

  4. Lorinthio

    Lorinthio

    Joined:
    Aug 7, 2015
    Posts:
    39
    According to this, which seems to be the same issue.

    It says to delete the script in your documents/project folder. Essentially where it would be on your disk. You'll need to reopen your project and remake the script. But this should fix your problem!

    In addition no problem! Most of the small bugs/issues like this can be found as unity has seen its fair share of users. So a little searching can go a long way. Won't always have bored guys like me on here ;)
     
  5. navaljosh

    navaljosh

    Joined:
    Aug 4, 2015
    Posts:
    8
    Yes i got that solution while diving in forums , but i really dint saw any files on my harddisk causing this issue, hence posted here :)
     
  6. Lorinthio

    Lorinthio

    Joined:
    Aug 7, 2015
    Posts:
    39
    Did you delete the obstacle.cs from the project folder?
     
  7. navaljosh

    navaljosh

    Joined:
    Aug 4, 2015
    Posts:
    8
    see i restarted Unity, checked any files in document/project/scripts
    Still same issue
     

    Attached Files:

  8. Lorinthio

    Lorinthio

    Joined:
    Aug 7, 2015
    Posts:
    39
    Ah that picture shows a different issue. You need to make a new script for the player, name it something. Then drag it to the player
     
  9. navaljosh

    navaljosh

    Joined:
    Aug 4, 2015
    Posts:
    8
    ok ill just jot down what i am doing .
    1. I have a player, i add a component -> a new script - > lets name it naval
    2. open naval.cs in editor and add code -> save
    3. Now what i see is this -> attaching image naval1
    4. this is the image when i click my player
    naval1.png naval2.png
     
  10. Lorinthio

    Lorinthio

    Joined:
    Aug 7, 2015
    Posts:
    39
    For lack of ideas, the final thing posted in that other forum was an antivirus was messing with his scripts. Otherwise I'm not sure =(. Wish I could help more than I have
     
  11. navaljosh

    navaljosh

    Joined:
    Aug 4, 2015
    Posts:
    8
    yes , i read that also.. ok i llok for this, thanks for taking interest, will post as soon as i find something.
     
    Lorinthio likes this.
  12. A.Killingbeck

    A.Killingbeck

    Joined:
    Feb 21, 2014
    Posts:
    483
    Right click project window->re-import all

    OR

    right click the script file giving problems -> reimport

    Edit: Actually, I just looked at your script file. The error is telling you exactly what is wrong. Your .cs file is named "obstacle" but your class name within the file is spelt with an Uppercase O, Obstacle.

    Both the name of the script and the main class within it must be exactly the same name
     
  13. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    Your scripts have to have the same name as the class inside of them, for MonoBehaviours. You're trying to load a component named "naval" but you've named the class inside of it "Player", and it has no idea what's going on.
     
  14. A.Killingbeck

    A.Killingbeck

    Joined:
    Feb 21, 2014
    Posts:
    483
    Ok, looking at the other screenshots you posted, you have the same problem everywhere. C# is case sensitive. The name of your .cs file should match exactly the name of the class within the file.
     
  15. navaljosh

    navaljosh

    Joined:
    Aug 4, 2015
    Posts:
    8
    Thanks all, as you guys pointed out , class n file name mismatch