✅ Class problem
Im new with C# and in my script im looking to call a script alr created but it won't work

66 Replies
What's the error?
after private i want to call my script ControllerPlayer but idk why this one is counting like a mistake and nothing work
What's the error?
PlayerController
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
There we go
Do you actually have a class named
PlayerController?
Are both the MoveLeft and PlayerController classes in the same namespace?if u post the definition of the PlayerController class we'll be able to figure out what's wrong quickly
No
Then how do you expect to use a class that does not exist?
bc it's not a class here i want to call
It's the script itself
Well you can't use much else as a type
so
yup! so -- when you "want to use your scripts on other scripts", you actually use classes!
That's not how C# works
Not whatsoever
C# has no concepts of files, for the most part
$helloworld
Get started with beginner tutorials
- Interactive text tutorial
- Video tutorial
- Fundamentals documentation
Start here
From the basics
So how the man that im watching got the access to call the script
Then try Unity
im lost
Im on it
Do you have VS Code set up for Unity?
im think yes
PlayerController seems like a built-in Unity class
$setupunity
$configureunityOh
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
it is
but idk why this one won't appear
Let me do a sc
there is no PlayerController here

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 nowhereIm following a course on unity and in this one you can have an access to this PlayerController

Can you post the contents of
PlayerController.cs?
$codeTo 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/What's that brace style lmao
not mine
But, yeah, seems they simply have a
PlayerController class
Which you seem to not haveSo the question now is how to have it
jcotton42
Can you post the contents of
PlayerController.cs?Quoted by
<@446416451230760990> from #Class problem (click here)
React with ❌ to remove this embed.
all ?
just hide sensitive parts that show your password etc
Just trying to see if there's a class definition in there.
ok...
(ideally you wouldn't have that kind of stuff in your code)
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


yeah! your type is called "Player" but you're trying to use something called "PlayerController"
But i just followed exactly what the guy was doing
best practice in Unity: Make classes have the same name as the scripts
Apparently not
Or the tutorial itself had an error
if this is a picture from the IDE of the guy whose tutorial you're watching, I would recommend a different tutorial 😛
Its the unity programming course to learn basics
But if u have better
that's no excuse for this bracket formatting imo 😛
you don't like that
how you prefere the bracket formatting ?
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.
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.
The C# convention of
I personally use
---
but
is NOT something that should contaminate the brain of someone who's just learning how to program
(aka Allman style)
everyone has their own style i mean
There is very much a standard for C#.
Nothing's stopping you from deviating, but like.
Why.
that's true
anyways ty for ur help
np, I still recommend a different tutorial 😛 Maybe the one I linked
hf!
Ty i'll do it later 🙂
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
https://docs.unity3d.com/2018.4/Documentation/ScriptReference/Networking.PlayerController.html
Here you can see it is considered "obsolute" in unity 2018