r/unity • • 3d ago

Coding Help I can’t figure out why I’m getting error code “CS0122” on Unity

Post image

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!

0 Upvotes

29 comments sorted by

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.

0

u/Ok_Illustrator_3539 3d ago

Thanks for the comment, I was able to figure it out!

2

u/eliormc 3d ago

It is private, change it to Public.

0

u/Ok_Illustrator_3539 3d ago

Change what? The only thing that’s private is the “OnTrigger” thing above it, and when I change it to Public it doesn’t help. I just left it as private because of what the tutorial had.

3

u/eliormc 3d ago

addscore() method inside Logic is private, it need to be like:

....

Public void addscore() {...}

...

2

u/Ok_Illustrator_3539 3d ago

Yes, you were right, thank you.

1

u/Ok_Illustrator_3539 3d ago

Nvm, I was able to get it.

1

u/wor-kid 3d ago

to the addscore method signature in LogicScript component

1

u/DarkAtheris 3d ago

Make the function addscore in LogicScript public

1

u/Ok_Illustrator_3539 3d ago

Thank you! I didn’t realise this was the issue.

1

u/BuzzardDogma 3d ago

It's an important lesson. Method and field access will be critical going forward, especially as you start trying to develop more complex systems.

1

u/Ok_Illustrator_3539 3d ago

I definitely have a lot to learn 😅 Immediately after this I ran into another error, but I was able to figure it out, it was one freaking capital letter. I get so mad when there’s a problem, but twice as happy when I solve it, so it’s worth it.

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.

1

u/Ok_Illustrator_3539 3d ago

I got it, thanks for the help!

1

u/abdulahad78 3d ago

You're welcome! Glad you got it working! :)

-3

u/[deleted] 3d ago

[removed] — view removed comment

4

u/Ok_Illustrator_3539 3d ago

I’d rather shoot myself, thanks,

2

u/No-Collar-Player 3d ago

Then don't shitpost..

1

u/Aethenosity 3d ago

This is not a shitpost. But saying Use AI is....

2

u/No-Collar-Player 3d ago

How is this not a shitpost?! He says he doesn't want to use ai, then just Google the error and literally the first stack overflow post explain to you how accessing methods works in the highest level of detail.. this is literally engagement baiting

2

u/Ok_Illustrator_3539 3d ago

Do you really think Googling it didn’t cross my mind? I have a (very basic) understanding of accessing methods, the problem ended up being in LogicScript, which Google never could’ve told me. Maybe AI could’ve suggested that, but what’s the point in that if I could just as easily ask others and actually learn rather than letting a robot rot my brain? I could potentially see a point in using AI to write tedious code, but when I’m actively trying to learn a new skill and troubleshoot (one of the best ways to learn, imo), why wouldn’t I try to problem solve and understand the issue to the best of my ability to actually further my knowledge on the subject.

1

u/PGSylphir 3d ago

Don't argue with AI bros. They don't expend the time to learn so they want to shame others that do in an effort to lower the overall threshold. It's all so they can feel less inferior.

It is a very simple issue indeed but you're doing the effort to learn without the use of AI, and that alone puts you miles above these shitheads.

2

u/Ok_Illustrator_3539 3d ago

I know I shouldn’t just give into these types of people, but oh my god does it grind my gears! You’re right though, and thanks for the reassurance 🥹

0

u/No-Collar-Player 3d ago

I'm pretty sure y all are bots

1

u/PGSylphir 3d ago

I'm pretty sure you can be diagnosed as regarded

1

u/EchoFieldHorizon 3d ago

This is someone wanting to engage with humans rather than talk to AI. What is the point of this community if you drive those people away? Why even talk about this at all in a public space? Get a grip, bro.

3

u/No-Collar-Player 3d ago

Brother this guy has private profile, this post reeks of karma farming holy shit. I don't mind real engagement with people but this is insanely low efort engagement baiting for probably malicious purposes after the karma is farmed holy shit

1

u/EchoFieldHorizon 3d ago

Found the real junior dev here. It’s you.