Error from Unity Manual TouchPhase

I’ve taken this straight from the Unity Manual and yet i have errors and I don’t know what they want me to do to fix them:

The end result that I want is for the player to be able to launch the ball AFTER touching the screen and choosing the direction, then releasing. Previously, I was having issues with the ball launching on start, due to there not being a touch.

Hi Amber,

Please note, it’s better to copy/paste your code and apply the code fencing characters, rather than using screenshots. Screenshots are ideal for displaying specific details from within a game engine editor or even error messages, but for code, they tend to be less readable, especially on mobile devices which can require extensive zooming and scrolling.

You also prevent those that may offer to help you the ability to copy/paste part of your code back to you with suggestions and/or corrections, meaning that they would need to type a potentially lengthy response. You will often find that people are more likely to respond to your questions if you make it as easy as possible for them to do so.

I think there might be missing the switch header in your code. If you don’t know what I mean, look for “switch” in the code example in the Unity documentation.

Hope this helps :slight_smile:


See also;

Sorryabout that

private void TrackTouch()
    {
        if (Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);
            {
                case TouchPhase.Began:
                    startPos = touch.position;
                    directionChosen = false;
                    break;

                case TouchPhase.Moved:
                    direction = touch.position - startPos;
                    break;

                case TouchPhase.Ended:
                    directionChosen = true;
                    break;
            }
        }
        if (directionChosen)
        {
            LaunchOnMouseClick();
        }
    }

I see a moment that mentions “touch phase.
switch (touch.phase)” but it follows // in the unity manual, thus I have no idea where I should actually put it in the code and how to format it all.

sorry, I now see, the //notes were separate from the switch method

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms