0
\$\begingroup\$

New to Unity and got this issue. I was watching a Brackey's video about topdown shooting and copying code as we go along. So I am really stumped as to why I am having this issue.

At 4:58 seconds he adds this script to the player and starts moving. When I add my script I get the "Can't add script" error.

I have read other posts about this and Have copied and pasted my script name and even tried changing it too. No luck. I have restarted Unity as well thinking it could be some kind of bug. Not that either. I will post my code down below if somebody can help me out that be so greatenter image description here

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Please use code markup for posting code and not images \$\endgroup\$
    – Zibelas
    Commented Aug 29, 2021 at 12:58
  • \$\begingroup\$ I'm unable to reproduce this problem with the code shown here. Writing a script with this name and exactly this text content, saving it, and dragging it onto an object adds the component correctly, as one would expect. As the error message says, you should check your Console tab for any compilation errors that could be preventing the PlayerMovement script from being recognized. If you've already fixed any compiler errors, try closing your project, deleting the Library folder to clear any cached info, and re-opening the project again. \$\endgroup\$
    – DMGregory
    Commented Aug 29, 2021 at 14:38
  • \$\begingroup\$ @DMGregory Thank you! I found out the solution after reading your comment. Nothing was wrong in that script the Console was erroring another script not allowing me to add any others. I deleted that third party script and suddenly I could add my script to the object. \$\endgroup\$
    – Pwhales
    Commented Sep 1, 2021 at 21:55
  • \$\begingroup\$ In future, please make sure you check your console for errors and fix or eliminate any unrelated errors before posting here. If you find an error you can't resolve or remove, and can't find solutions to it when you search for the error message text, then be sure that error message is included in your question. \$\endgroup\$
    – DMGregory
    Commented Sep 1, 2021 at 21:59
  • \$\begingroup\$ @DMGregory Thanks for the information. Like I said I am new to this so I appreciate the help and advice. Will do in the future. \$\endgroup\$
    – Pwhales
    Commented Sep 1, 2021 at 22:01

1 Answer 1

1
\$\begingroup\$

Wasn't anything to do with the script name or my code. In the project folder in unity I had another script that had a compile error and the Console would not allow me to add any scripts until that was resolved. By deleting that 2nd script I could add the script correctly and ran as one would expect it to. :)

\$\endgroup\$
1
  • \$\begingroup\$ If this solved your issue, you could mark this answer as accepted. \$\endgroup\$
    – liggiorgio
    Commented Sep 4, 2021 at 0:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .