C
C#2y ago
EmoEmu_69

❔ Use of unassigned local variable

I'm getting an error saying "Use of unassigned local variable "Input"" I just followed a tutorial on scripting a camera that follows your cursor, and it seemed to work fine for the dude in the video
37 Replies
Angius
Angius2y ago
That has no right to work Since you're using values of Input... to construct a new value for the Input You sure the local variable shouldn't be named input instead? And that Input isn't some property of MonoBehavior?
Anton
Anton2y ago
Input is a static class
Angius
Angius2y ago
Close enough lol
EmoEmu_69
EmoEmu_69OP2y ago
gonna be honest, Idk what most of that meant
Anton
Anton2y ago
rename your local variable to input
EmoEmu_69
EmoEmu_69OP2y ago
ok
Angius
Angius2y ago
And that's why I believe it's best to learn C# first, Unity second
EmoEmu_69
EmoEmu_69OP2y ago
I prolly would've gone that way if I were learning on my own, but it's for a class I tried that and it just gave the same error but with the new name
Angius
Angius2y ago
What's the error?
Anton
Anton2y ago
GetAxis should still be called on Input
Angius
Angius2y ago
And what's the code now?
EmoEmu_69
EmoEmu_69OP2y ago
Use of unassigned local variable "Input"
Anton
Anton2y ago
you didn't save the file maybe
EmoEmu_69
EmoEmu_69OP2y ago
I haven't changed it since making the post
Angius
Angius2y ago
uh
EmoEmu_69
EmoEmu_69OP2y ago
I tried saving it a lot
Anton
Anton2y ago
?? rename the variable?
Angius
Angius2y ago
So you didn't fix the code... and the code isn't fixed Surprise, I guess..?
EmoEmu_69
EmoEmu_69OP2y ago
other than that, I meant my bad
Anton
Anton2y ago
show it
EmoEmu_69
EmoEmu_69OP2y ago
ok
Anton
Anton2y ago
$code
MODiX
MODiX2y ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat If your code is too long, post it to: https://paste.mod.gg/
Angius
Angius2y ago
Did you do it in both places? Because you're creating the variable, and then you're returning it
EmoEmu_69
EmoEmu_69OP2y ago
BlazeBin - tgjkcvlbxgva
A tool for sharing your source code with the world!
EmoEmu_69
EmoEmu_69OP2y ago
this is after making the change to "Input" you suggested
Angius
Angius2y ago
Rename just the variable
EmoEmu_69
EmoEmu_69OP2y ago
oh I think I might be dumb
Anton
Anton2y ago
Input.GetAxis is a function access on a static class
Angius
Angius2y ago
Angius
Angius2y ago
Green good change red bad change
EmoEmu_69
EmoEmu_69OP2y ago
ah gotcha that fixed it, thanks guys!
Anton
Anton2y ago
also $unity
Angius
Angius2y ago
The Unity server people often send people to our server, when the issue has to do with the basic understanding of C# lol
EmoEmu_69
EmoEmu_69OP2y ago
ah thanks
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server