- Home /
Why won't my Unity project allow me to use scripts?
So basically every time that I open my unity document, i start working. so far, bc im new with unity and game making altogether, i don't know a ton but enough to play around with it. if i go to add component in an object in my hierarchy, it allows to me to edit and work with the script, but it never works properly. it always says that the components are wrong or something. The same goes for when i drag a C# script onto an object, except it just says that It doesn't inherit a native class that manage a script, even if i haven't edited it, or if i have and it's all ready to go. this also randomly started happening and i'm not sure if its me or the installation.
Does anybody know how to fix this?? I have a deadline for my project extremely soon, so the sooner i get a response the better. Thank you!
~Emily
So I fixed it for the time being, and it should work properly for the time I need, but I would still appreciate an answer in case it happens again. thank you again!
~Emily
Answer by UnityM0nk3y · Apr 06, 2021 at 09:28 AM
Hey Emily =)
This sounds like a common "naming"/"renaming" error.
It is good practice to use "Camel Case" to name scripts: thisIsCamelCase > (no spaces, and try to use as little as possible numbers + symbols).
Seeing that you said you are new, try this steps to create and edit a script:
Click on the component you want to add the script to.
Say "Add Component" > and at the bottom > "New Script".
Give your script a sensible name, and use camel case syntax for eg: "myCharacterController".
Now double click on the new "script field" on the object, and it should launch Visual Studio.
Also always make sure that this is at the top of your code:
public class myCharacterController: MonoBehaviour { }
And the myCharacterController should be exactly the same as the name of your script. If you want to "rename" your script, it is safer to create a new one, and copy + paste everything in between the "public class" into it.
Hope this helps
~ Monkey =)
@UnityM0nk3y Thank you so much! I tried it and it worked really well. Thank you again, I really appreciate it. Have a good day!