C
C#•2mo ago
Me

2D Movement

I am trying to make a code that moves left and right for unity in a 2D project, but there is a weird error occuring. Can someone help? using UnityEngine; public class Movement : MonoBehaviour { public float moveSpeed = 3f; public float jumpHeight; private KeyCode lastHitKey;
void Start() { } void Update() { if(Input.GetKeyDown (KeyCode.D)) { if(lastHitKey ==KeyCode.D) { movement.x = (transform.rightTime.deltaTime-moveSpeed).x; } } if(Input.GetKeyDown (KeyCode.A)) { if(lastHitKey ==KeyCode.A) { movement.x = (transform.rightTime.deltaTimemoveSpeed).x; } } } }
26 Replies
tacosontitan
tacosontitan•2mo ago
Describe the error that's occuring. At first glance, you're never giving lastHitKey a value, so that's a problem.
FusedQyou
FusedQyou•2mo 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.
šŸ’” 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 • :JTRaider: JetBrains Rider • ā“ Other/None
And if it isn't a syntax error, then please $paste your code properly.
MODiX
MODiX•2mo ago
If your code is too long, you can post to https://paste.mod.gg/, save, and copy the link into chat for others to see your shared code!
FusedQyou
FusedQyou•2mo ago
I just remembered * also makes test italic in which case it might not be a syntax error. Either way more context is needed
Me
MeOP•2mo ago
so what exactly do I do to fix it? Im new to the whole unity thing so sorry
FusedQyou
FusedQyou•2mo ago
For starters share the error You can find it in the Unity console in the actual Unity editor application If it's not there you should check your Code editor's console instead which will display one
Me
MeOP•2mo ago
its saying that x on lines 19 and 26 is not defined
FusedQyou
FusedQyou•2mo ago
Share the whole thing please Not small bits, the whole thing Matter of fact, screenshot the whole editor where your code is so I can verify it's not actually configured @Me If not, you will have to configure it in that case. Your issue will be solved then anyway
Me
MeOP•2mo ago
kk
Me
MeOP•2mo ago
@FusedQyou
No description
No description
FusedQyou
FusedQyou•2mo ago
Yes so it's not configured We actually have a command now so let me use that one šŸ˜Ž You have to configure your editor to work with Unity. $configureunity šŸ‘‡
MODiX
MODiX•2mo 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
FusedQyou
FusedQyou•2mo ago
I do want to advice you to switch to either Visual Studio or Jetbrains as the support for Unity will be much better.
Me
MeOP•2mo ago
I’m using VS is the thing
FusedQyou
FusedQyou•2mo ago
Well, configure it When you did, the editor will actually show you exactly what is wrong
Me
MeOP•2mo ago
it was already configured
No description
Me
MeOP•2mo ago
No description
FusedQyou
FusedQyou•2mo ago
It's not configured if the error you get is not from the editor I don't know how VSCode works with Unity. I strongly suggest you switch to Visual Studio or Jetbrains Rider
Me
MeOP•2mo ago
ok, I'll try that brb yeah, i'm on mac so VS wont work and Rider isn't my style I found out what was happening though, turns out I had the C# language pack disabled in VS code exstentions
FusedQyou
FusedQyou•2mo ago
So does it show you the issue now?
Me
MeOP•2mo ago
yeah, its saying there's not definition for x (cs0117)
FusedQyou
FusedQyou•2mo ago
Yes because movement is a variable that you used but it's not defined anywhere
Me
MeOP•2mo ago
So how should I define 'movement'?
FusedQyou
FusedQyou•2mo ago
How am I supposed to know? It's your code If that's confusing to you I wonder if Unity is a good idea to use with your experience
Me
MeOP•2mo ago
i figured it out You were right, it was a configuring error and turns out that my mac is too out dated to install the debugger for C# but I fixed the code
FusedQyou
FusedQyou•2mo ago
Nice Well your editor is configured now so that will help you a ton here

Did you find this page helpful?