Okay, so after about an hour of Googling, I got nothing. So here I am.
I have a w.i.p. script that’s just for moving about the player character, and the Monobehaviour issue has come up. But I don’t see any issues with the Monobehaviour, and the script name is the same as the class name (which is what almost everyone said the problem was). I even reopened Unity to see if that would work, and it didn’t. And I get a popup whenever I try to use the code saying ‘Can’t add script behaviour AssemblyInfo.cs. The script needs to derive from MonoBehaviour!’. I tried naming the code ‘AssemblyInfo’ and trying that, too. Nada.
I copied this from a tutorial, as I’m just starting to learn Unity. Am I missing something here, or should I just find another tutorial?
using UnityEngine;
public class PlayerController : MonoBehaviour {
Rigidbody rb;
public float speed = 10.0f;
void Start () {
rb = GetComponent<Rigidbody>();
}
void Update () {
if (Input.GetKey (KeyCode.RightArrow) )
{
rb.velocity = transform.right * speed;
}
}
}
So, just to be sure, the file that your script is in is definitely named PlayerController.cs, and definitely not AssemblyInfo.cs, right?
If the error message is actually calling your file by a different name than it actually is, then there could be some screwed-up cached, compiled assembly. Try right-clicking on the script in your project panel and selecting the menu option (i think it’s “reimport script” or “reimport asset” or something like that). See if that fixes the problem
Yep, it’s named PlayerController.cs, I made sure of that (I made a separate file for the name change method to test it out and it still didn’t work so…).
That’s good. That menu option simply forces Unity to recompile your script (Unity is supposed to do this automatically but sometimes it bugs-out). Try it whenever you get a weird nonsense error about script that doesn’t exist or if Unity is complaining about an error that you already fixed. Occasionally