I’m writing the following code in the Editor: Using UnityEngine; Using System.Collections; Public class new: MonoBehaviou { Public int runspeed; //Use this for initialization Void Start () { } //Update is called once per frame Void Update () { } } When I try to attach the script to the main camera in Hierarchy view I get an error message saying: Can’t add script Can’t add component “new” because it doesn’t exist. Check to see if the file name and class name match. I'm learning Unity reading from a book. I don’t know what I’m doing wrong. Could you please help me?
I haven't tried myself but I doubt you can name a class "new" since the Word "new" already is defined in C# as a keyword. Try changing the name of the class and see if it works, I Think your problem is that your code can't compile and therefore unity won't allow you to add the script to your gameobject.
Try copying the code inside of this class to notepad or something, then delete the whole file, create again and paste the code in it.
The first thing you should do is make your code syntactically correct. ... otherwise it won't compile. Perhaps something like : Code (CSharp): // file: news.cs using UnityEngine; using System.Collections; public class news : MonoBehaviour { public int runspeed; //Use this for initialization private void Start() { } //Update is called once per frame private void Update() { } } I assume your file name is the same as the class name??