C
C#4d ago
Rethae

✅ Brand new to C# and Unity

For some reason my else statement isnt attaching to the previous if. Im wondering if i missed something or not. I recently set up sprinting right before it, and heard you can only put one update per class, so i have to cram all my movement updates into this one area, and it looks just like a bunch of if else statements spammed everywhere.
No description
15 Replies
taner.
taner.4d ago
U can do maybe a switch case for the key?
Rethae
RethaeOP4d ago
In English? I literally just started learning unity and c# after getting off work last night (and am at work right now too) Just wondering what exactly you mean by switch case
taner.
taner.4d ago
if and switch statements - select a code path to execute - C# refer...
The if and switch statements provide branching logic in C#. You use if, else and switch` to choose the path your program follows.
Rethae
RethaeOP4d ago
Thanks :rethaepwease:
Kiel
Kiel4d ago
little late but you have a random semicolon on the end of the line with the if you've effectively written
if (Input.GetKey(KeyCode.LeftControl))
{
// this is what the loose ; effectively does
}

{
playerscale = crouchHeight; // this is now happening regardless of the "if"
}
else // error - the "if" block is no longer valid here
if (Input.GetKey(KeyCode.LeftControl))
{
// this is what the loose ; effectively does
}

{
playerscale = crouchHeight; // this is now happening regardless of the "if"
}
else // error - the "if" block is no longer valid here
Buddy
Buddy4d ago
I suggest you learn C# without a game engine, it will be significantly harder to learn C# from Unity. $helloworld
Buddy
Buddy4d ago
Start from there
Rethae
RethaeOP4d ago
But I have so many ideas, my brains gonna explode I must code
taner.
taner.4d ago
Learning by doing
Rethae
RethaeOP3d ago
I’ve been reading over this and it talks about using values later in code Ontop of that I remember in unity the public/private method Do returns/public carry over scripts, or stay within there own confined spaces. I’ve seen some people mess with speed values for movement, for example. One person set all of them to public, while the other set 80% of them to private I’ve read that these allow them to be accessed on a broad basis, and likewise be accessed only within its enclosed space, but how does that actually work. If you have a private move speed value set up, does that mean if you make an “enemy” for example, and give them the same private move speed value, they can be two different values? Or what if you make one public and the other private.
No description
Rethae
RethaeOP3d ago
I’m very bad at picking up languages and such, and it’s been evident ever since I stopped taking my focus medication, but my old doctor has moved away and I never liked it anyhow. If yall could, in any way, dumb this down for me, I’d appreciate it
Quest o()xx[{:::::::::::::::>
These kind of questions are perfect to ask Ai. I find they are really good at explaining programming concepts. You can even ask it to explain to you like you’re a 5 years old, or use analogies and such. Just don’t use it to generate code for you, unless you know exactly and understand perfectly what it does. Also if you want to learn to program while making games, you should look up for MonoGame which is a free open source C# framework for game development. Its uses a "code-first" approach. This means that, unlike game engines such as Unity or Unreal Engine which provide visual editors and interfaces for game creation, it focuses on writing code to control all aspects of the game.
Karan
Karan3d ago
Looks like you got a ; at end of if on line 85 That is usually an end of statement for c#
Unknown User
Unknown User3d ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?