Question How would I write a "GetKeyDown" Input as a Variable

creampuff1

Member
Joined
Aug 22, 2023
Messages
6
Programming Experience
Beginner
sorry if its a stupid question or if I phrased it wrong im still very new.

Unity is saying,
"The left-hand side of an assignment must be a variable, property or indexer"
However I cant figure out how to make into one of those

The part thats causing the error is,
C#:
 if (Input.GetKeyDown(KeyCode.LeftShift) && Sprinting = false)
        {
            Debug.Log("Sprinting True");
            Sprinting = true;
            MoveSpeed = 250;
        }
Does anyone know how I can rewrite this so it works?
 
Last edited by a moderator:
Write this on a post it and put it on your monitor:

C#:
= is for assignment 
== is for comparison
 
I'll repeat what I said in our OP's other thread:
It looks like they are trying to climb two steep learning curves at the same time: learning the C# language, and learning how to use Unity. This makes things four times as hard.
 
So your previous thread was due to your using == rather than = and this one is because you're using = instead of ==. I have to agree with @Skydiver, you're trying to do complex things before you have a proper understanding of the basics. You should stop what you're doing, learn C# to at least a standard where you're not consistently making such basic errors, then go back to Unity. You probably think that doing it that way will take longer but it won't, because you won't be holding yourself back from understanding Unity by your lack of understanding of C#.
 

Latest posts

Back
Top Bottom