✅ Class problem

Im new with C# and in my script im looking to call a script alr created but it won't work
No description
66 Replies
Angius
Angius4w ago
What's the error?
elephΛntique
elephΛntiqueOP4w ago
after private i want to call my script ControllerPlayer but idk why this one is counting like a mistake and nothing work
Angius
Angius4w ago
What's the error?
elephΛntique
elephΛntiqueOP4w ago
PlayerController
Angius
Angius4w ago
That answers a "where" question, and I can see it from the red underline Not a "what" question Hover your mouse over the underlined bit, check the build log, check the errors panel or whatever it is that VS Code has For a specific error message
elephΛntique
elephΛntiqueOP4w ago
No description
Angius
Angius4w ago
There we go Do you actually have a class named PlayerController? Are both the MoveLeft and PlayerController classes in the same namespace?
Lyrcaxis
Lyrcaxis4w ago
if u post the definition of the PlayerController class we'll be able to figure out what's wrong quickly
elephΛntique
elephΛntiqueOP4w ago
No
Angius
Angius4w ago
Then how do you expect to use a class that does not exist?
elephΛntique
elephΛntiqueOP4w ago
bc it's not a class here i want to call It's the script itself
Angius
Angius4w ago
Well you can't use much else as a type so
Lyrcaxis
Lyrcaxis4w ago
yup! so -- when you "want to use your scripts on other scripts", you actually use classes!
Angius
Angius4w ago
That's not how C# works Not whatsoever
Lyrcaxis
Lyrcaxis4w ago
C# has no concepts of files, for the most part
Angius
Angius4w ago
$helloworld
MODiX
MODiX4w ago
Get started with beginner tutorials - Interactive text tutorial - Video tutorial - Fundamentals documentation
Angius
Angius4w ago
Start here From the basics
elephΛntique
elephΛntiqueOP4w ago
So how the man that im watching got the access to call the script
Angius
Angius4w ago
Then try Unity
elephΛntique
elephΛntiqueOP4w ago
im lost Im on it
Angius
Angius4w ago
Do you have VS Code set up for Unity?
elephΛntique
elephΛntiqueOP4w ago
im think yes
Angius
Angius4w ago
PlayerController seems like a built-in Unity class $setupunity $configureunity
elephΛntique
elephΛntiqueOP4w ago
Oh
MODiX
MODiX4w ago
You have a syntax error in the code which suggests you don't have your editor configured. You need to configure it before you do anything Unity related.
:bulb: IDE Configuration If your IDE is not autocompleting code or underlining errors, please configure it. Select one: • :visualstudio: Visual Studio (Installed via Unity Hub) • :visualstudio: Visual Studio (Installed manually) • :vscode: VS Code • :jetbrains: JetBrains Rider • :question: Other/None
elephΛntique
elephΛntiqueOP4w ago
it is but idk why this one won't appear Let me do a sc
elephΛntique
elephΛntiqueOP4w ago
there is no PlayerController here
No description
Angius
Angius4w ago
Huh, I guess Unity doesn't have a built-in PlayerController after all. All I can see is tutorials how to make one, based on MonoBehaviour So whatever tutorial you're going through, probably had a segment on making the PlayerController You have a file named like so, after all I assume it didn't come out of nowhere
elephΛntique
elephΛntiqueOP4w ago
Im following a course on unity and in this one you can have an access to this PlayerController
elephΛntique
elephΛntiqueOP4w ago
No description
jcotton42
jcotton424w ago
Can you post the contents of PlayerController.cs? $code
MODiX
MODiX4w ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
Angius
Angius4w ago
What's that brace style lmao
elephΛntique
elephΛntiqueOP4w ago
not mine
Angius
Angius4w ago
But, yeah, seems they simply have a PlayerController class Which you seem to not have
elephΛntique
elephΛntiqueOP4w ago
So the question now is how to have it
MODiX
MODiX4w ago
jcotton42
Can you post the contents of PlayerController.cs?
Quoted by
<@446416451230760990> from #Class problem (click here)
React with ❌ to remove this embed.
elephΛntique
elephΛntiqueOP4w ago
all ?
Lyrcaxis
Lyrcaxis4w ago
just hide sensitive parts that show your password etc
jcotton42
jcotton424w ago
Just trying to see if there's a class definition in there.
elephΛntique
elephΛntiqueOP4w ago
ok...
jcotton42
jcotton424w ago
(ideally you wouldn't have that kind of stuff in your code)
elephΛntique
elephΛntiqueOP4w ago
there isn't i just don't understand why he pulled that from nowhere everything was fine i change for the Player class that existe in the monoBehaviour PlayerController and it seems to work
elephΛntique
elephΛntiqueOP4w ago
No description
elephΛntique
elephΛntiqueOP4w ago
No description
Lyrcaxis
Lyrcaxis4w ago
yeah! your type is called "Player" but you're trying to use something called "PlayerController"
elephΛntique
elephΛntiqueOP4w ago
But i just followed exactly what the guy was doing
Lyrcaxis
Lyrcaxis4w ago
best practice in Unity: Make classes have the same name as the scripts
Angius
Angius4w ago
Apparently not Or the tutorial itself had an error
Lyrcaxis
Lyrcaxis4w ago
if this is a picture from the IDE of the guy whose tutorial you're watching, I would recommend a different tutorial 😛
elephΛntique
elephΛntiqueOP4w ago
Its the unity programming course to learn basics But if u have better
Lyrcaxis
Lyrcaxis4w ago
that's no excuse for this bracket formatting imo 😛
elephΛntique
elephΛntiqueOP4w ago
you don't like that how you prefere the bracket formatting ?
Lyrcaxis
Lyrcaxis4w ago
Unity Learn
Unity Learn
Free tutorials, courses, and guided pathways for mastering real-time 3D development skills to make video games, VR, AR, and more.
elephΛntique
elephΛntiqueOP4w ago
Unity Learn
Unity Learn
Free tutorials, courses, and guided pathways for mastering real-time 3D development skills to make video games, VR, AR, and more.
jcotton42
jcotton424w ago
The C# convention of
class C
{
code
}
class C
{
code
}
Lyrcaxis
Lyrcaxis4w ago
I personally use
class C {
code
}
class C {
code
}
--- but
class C {
code }
class C {
code }
is NOT something that should contaminate the brain of someone who's just learning how to program
jcotton42
jcotton424w ago
(aka Allman style)
elephΛntique
elephΛntiqueOP4w ago
everyone has their own style i mean
jcotton42
jcotton424w ago
There is very much a standard for C#. Nothing's stopping you from deviating, but like. Why.
elephΛntique
elephΛntiqueOP4w ago
that's true anyways ty for ur help
Lyrcaxis
Lyrcaxis4w ago
np, I still recommend a different tutorial 😛 Maybe the one I linked hf!
elephΛntique
elephΛntiqueOP4w ago
Ty i'll do it later 🙂
krubbles
krubbles4w ago
I don't think the PlayerController class exists in unity anymore as far as i can tell, it was depricated more then 5 years ago
krubbles
krubbles4w ago

Did you find this page helpful?