Cant add script becuase of error
every time i try to attach my script to a sphere (im taking a class), i get the error message that says "Can't add script component 'move' because the script class cannot be found. Make sure that there are no compile errors and that the file name and class name match." i have tried many things from retyping my code and deleting things but i dont know how to fix this. ill put my code so you might be able to see what is wrong. my names match too.
using System.Collections;
using System.Collections.Generic;
using System.Net.Sockets;
using UnityEngine;
public class Move : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.Translate(Input.GetAxis("Horizontal"), 0, 0);
}
}
Is the file named
$$anonymous$$ove.cs
(notmove.cs
)?Do you have any other error in the console?
it is named "$$anonymous$$ove". i even checked. i don't think i have any errors. nothing is underlined in red. ive followed videos and i have deleted the file and created a new one but it stayed as the same error.
i don't think i have any errors. nothing is underlined in red
Look at Unity's console tab to check whether you have compiling errors.
Answer by Dizy · May 14, 2020 at 02:43 PM
That's a basic error, some basic guidelines to fix that :
Check your Class name and file name
Recompile and check IDE output
Add namespace based on file location
Check if you dont have another file with the same name
@Dizy my class and file name match and im following along a class and i named the file the same as the class said to and the $$anonymous$$cher didnt run into any errors. Ill try to recompile and check the output. can you tell me how to do that? im new to Unity sorry.
Answer by CSPAG · May 14, 2020 at 09:01 PM
I have a feeling the names don't match, they are case and space sensitive. I can see in the code you have an upper case Move public class Move : MonoBehaviour
but in the error message you have a lower case move
Can't add script component 'move'
both of the names start with an uppercase $$anonymous$$. there is no space in the "$$anonymous$$ove" file.
i think i forgot to type an upper case "$$anonymous$$ove" in the error message. i know it is upper case either way. thanks for the help though.