- Home /
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
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?
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 !
is you script named "$$anonymous$$yClass" in the editor?
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 !
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 !
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???
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.