Multiple conditions - what am I missing?

So I’ve been mostly doing old Gamemaker-stuff and what not before, and not too much of Unity in terms of scripting. But I’m basically trying out the basics and trying to start from somewhere. However - I can’t for the world understand what I am missing (I’m just trying to check double conditions for pushing both right and left keys). Unity says “and” doesnt exist. Am I totally writing this wrong to check double conditions? I’ve tried && also without luck, as Unity says that doesnt exist either. :stuck_out_tongue:

Any help is greatly appreciated.

 if (Input.GetKey("right")) and (Input.GetKey("left"))
                {
                 transform.Translate(1,0,0,Space.World);
                }

In C#, and is not a thing. You want &&. Also, your parentheses seem a bit mismatched. Try this:

        if (Input.GetKey("right") && Input.GetKey("left"))
        {
            transform.Translate(1, 0, 0, Space.World);
        }

Here’s a list of the logical operators in C#.

2 Likes

This is completely wrong. You don’t need () to use “and” and you’re closing the if with that )) in the “right” portion. It goes something like this:
if (Input.GetKey("right") && Input.GetKey("left"))

But this indicates you want both keys! I’m not sure you want that.

2 Likes

Thank you, both mopthrow and Lurking-Ninja. I works now with the help of you! Thanks for the explanations, they’re helpful, I’m very grateful. :slight_smile:

1 Like