0

I tried everything online the class name is the same as the file name but I keep getting this error, and also the console is also giving me nothing.

enter image description here

enter image description here

Unity version: 2019.2.12f1

this error appeared when trying to add script to object :

enter image description here

2
  • as Chev explains, simply (1) delete the file (2) start again, but the file name must be the same as the class name Commented Nov 17, 2019 at 18:20
  • Also try a name OTHER THAN "Player". there may be some weird conflict. Try "SedPlayer" or anything else. Commented Nov 17, 2019 at 18:21

1 Answer 1

1

OK, what this probably means is that the filename and class name are different - this happens when you rename files outside unity and always recommend you rename within Unity and keep the class name and file name in sync.

Check that the class name, Player, matches the file name and also refresh the folder within unity:

public class Player : MonoBehaviour {

enter image description here

UPDATE

Not to overstate the obvious, also confirm you have no compilations errors in your console. Access the console via window -> console

Sign up to request clarification or add additional context in comments.

5 Comments

i did as you told me and i double cheked but no success i keep getting the same error
Then you can a script compilation error. Open the Unity console: window > console and check that you do not have errors in the script when you try to start the game. Let me know if that is the issue and I will update the answer for others.
Don't share the code - just confirm there are no compilation errors in your console as per the comment above
there is no error and the console shows nothing (check the image in the answer)
There is an error - it cannot find the asset. Unity keeps track of assets internally so not good to manage the filesystem outside of unity. You can also try Assets > Reimport, but probably best to just delete, save then create another

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.