r/unity • u/Ok_Illustrator_3539 • 3d ago
Coding Help I can’t figure out why I’m getting error code “CS0122” on Unity
This is the first coding I’ve ever done in my entire life, so if the answer is ridiculously obvious, please don’t flame me.
So, I’m following a flappy bird tutorial to try and get a feel for things, and I’ve followed every single line of code to the absolute T. Not even a capital letter is out of place.
I got the error “LogicScript.addscore()’ is inaccessible due to its protection level.” I’ve gone through everything, and it’s all public, save for the “private void” above it, and when changed it didn’t help.
I looked through the comments for trouble shooting help, as another comment had helped me with different issue, but all suggestions for this problem didn’t help.
If it makes a difference, I’m on Unity 6.3 and Visual Studio 2022, using C-Sharp. Any help is appreciated!
Update : I didn’t specify “void Addscore()” as Public, problem solved! Thanks for the comments!
12
u/PGSylphir 3d ago
We can't see LogicScript because you didn't post it, but the error clearly says what the issue is. The method is not accessible. It's likely not public.
Also, next time use print screen. Photos of the monitor are infuriating.
2
u/eliormc 3d ago
It is private, change it to Public.
1
u/DarkAtheris 3d ago
Make the function addscore in LogicScript public
1
u/abdulahad78 3d ago
CS0122 typically means the method cannot be reached from the place where you are calling it. Check that addscore() is declared as void addscore(). Also check that the spelling and capitalization match in both scripts. If it is already public, can you share both scripts? The problem may be in how the method's being accessed.
-3
u/[deleted] 3d ago
[removed] — view removed comment