How can I get touch input in my game?

I just need to detect a input of touch (Anywhere not just a certain part) for my game. I feel like im doing this right its probally just the way that I wrote this if statement.

        if (Input.GetKeyDown(KeyCode.Space) && (TouchingGoal == true) && (GameStarted == true) || (Input.GetTouch) && (TouchingGoal == true) && (GameStarted == true))
        {
            Score = Score + 1;
            noise2.Play();
        }

I get an error and it says I cant use && after the Input.GetTouch

“Operator ‘&&’ cannot be applied to operands of type ‘method group’ and ‘bool’”

Also I am kind of new to unity so be nice lol!

Rather than ram it all into one line, try this approach:

  • make some temporary variables to store possible input

  • read input from keyboard into the variables

  • read it from touch into the variables

  • ready it from somewhere else too if you like

  • now act on those variables

If you have more than one or two dots (.) in a single statement, you’re just being mean to yourself.

How to break down hairy lines of code:

http://plbm.com/?p=248

Break it up, practice social distancing in your code, one thing per line please.

“Programming is hard enough without making it harder for ourselves.” - angrypenguin on Unity3D forums

“Combining a bunch of stuff into one line always feels satisfying, but it’s always a PITA to debug.” - StarManta on the Unity3D forums

Please know that this isn’t a 2D related post so please try to use the dedicated forums provided. In this case, I would recommend using the Scripting or Getting Started forums.

I’ll move your post for you.

Thanks.

its because you cant use input.gettouch that way, you should do “Input.touchCount > 0” if you just want to see if the screen is getting touched

More-generally stated: