• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This post has been wikified, any user with enough reputation can edit it.
avatar image
4
Question by Micky54 · Mar 10, 2015 at 01:57 AM · script error

Roll-a-ball Script Refuses to accept Monobehaviour

basically I followed the C# script and every time I save it and add it it continues to say that there is no MonoBehaviour Scripts in file or names do not match ... help please ... I just want this to work and sorry cannot sort this out

Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image maccabbe · Mar 10, 2015 at 01:57 AM 1
Share

This sounds like your class name isn't the same as your filename for a class that inherits $$anonymous$$onobehaviour. Can you please provide your script and the filename that the script is in?

avatar image Pokem Up · Mar 10, 2015 at 10:55 PM 0
Share

I have the same problem.

In the video "$$anonymous$$oving the player - 02", after he saves his script he goes into playmode to move his ball.

But when I try to do the same, I get the message "All compiler errors have to be fixed before you can enter playmode!"

Also I get the following message in the console : "No $$anonymous$$onoBehavior scripts in the file, or their names do not match the file name."

Here is the script I used :

 using UnityEngine;
 using System.Collections;
 
 public class $$anonymous$$yClass : $$anonymous$$onoBehaviour 
 {
     void FixedUpdate ()
     {
         float moveHorizontal = Input.GetAxis ("Horizontal");
         float moveVertical = Input.GetAxis ("Vertical");
 
         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
 
         Rigidbody.AddForce (movement);
     }
 }

Please help !

avatar image Kerihobo · Mar 10, 2015 at 11:04 PM 1
Share

is you script named "$$anonymous$$yClass" in the editor?

avatar image Pokem Up · Mar 11, 2015 at 05:40 PM 1
Share

Yes it is. I also updated my code slightly with advices from the $$anonymous$$ching forum, like so :

 using UnityEngine;
 using System.Collections;
 
 public class $$anonymous$$yClass : $$anonymous$$onoBehaviour {
     
     public float speed;
     
     void FixedUpdate ()
     {
         float moveHorizontal = Input.GetAxis ("Horizontal");
         float moveVertical = Input.GetAxis ("Vertical");
         
         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
         
         GetComponent<Rigidbody>().AddForce(movement * speed * Time.deltaTime);
     }
 }

The good news is the ball now slowly roll along the Z axis, by I still have no control over its movement !

avatar image attimsi · Mar 11, 2015 at 09:01 PM 0
Share

I have the same problem.

I did exactly like in the video "$$anonymous$$oving the player - 02". When I try to type code "rigidbody." I can not find function "AddForce()" in helper. There are several items like destroy object and that's it.

If I manually type "rigidbody.addforce" and try to run the game I get the message "All compiler errors have to be fixed before you can enter playmode!".

avatar image Pokem Up · Mar 12, 2015 at 12:36 AM 1
Share

Its working ! I changed the speed to 100 in the inspector, and now everything is working perfectly. I dont have any errors, and I understood that I had control of the ball all along, it was just moving so slowly I though it was just rolling on its own !

I can now continue on with the tutorial !

Thanks a lot $$anonymous$$erihobo !

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Kerihobo · Mar 10, 2015 at 02:08 AM

it's important that your script is allowed to inherit from monobehaviour which is a base class in the UnityEngine namespace.

to inherit from monobehaviour, your script must at least look like the following:

 using UnityEngine;
 using System.Collections;
 
 public class MyClass : MonoBehaviour
 {
 }

did you accidentally remove the "using UnityEngine;" from the top???

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Kerihobo · Mar 11, 2015 at 08:05 PM

i dont get it.... it looks like it should work... something else not in this script could be wrong. So it doesn't throw any errors? try resetting your rigidbody component in the inspector. or try setting speed to something like 10000.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

'parent' is not a member of 'Object'. 1 Answer

Csharp script parsing error 2 Answers

my STFPSC script has errors can anyone help me? 0 Answers

Object reference not set to an instance of an object error. 1 Answer

AddComponent() is adding 64 instances of my script to my GO 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges