Make sure file name and class name match
I'm fairly new at Unity, (and by fairly new I mean VERY new) and I got this error when writing the script for a... um... thing named Health_box. When I got the error, I changed the line to "public class Health_box : MonoBehavior" and saved it. I went back into Unity (im using Microsoft Visual Studio btw) and tried to attach the script to Health_box. However, because I changed the name of the class to Health_box instead of whatever I had before, I got a lot of errors on the screen, and of course this meant that I couldn't attach to script.
I need a way of changing the class without getting a bunch of errors, or at least a trick to allow me to attach the script even when there are errors. Anyone have any answers?
Answer by TBruce · Dec 16, 2016 at 11:24 PM
When you change the name of a class you need to change the file name to match. The best way to do that is from within Unity itself in the project tab.
Could you then close this question so that noone else answers it. And, if you do not $$anonymous$$d could you please be so kind as to click the "Accept" button above to accept the answer? Thank you!
Answer by ankitkcapp11 · Jul 12, 2020 at 08:33 AM
check if there are compile errors or not ???It is mainly caused due to compile errors....@ankitkcapp11
Your answer
Follow this Question
Related Questions
"Clipping", "Jumping" UI slider, attached to the 2d game object ( health bar) 0 Answers
Attaching an object to the OVR Camera? 1 Answer
How to attach one object to another without parent-child relationship? 0 Answers
How to attach a GameObject to a Prefab that has many scripts attached? 0 Answers
Make GameObject “attach” properly? 0 Answers