Share via

error CS1513: } expected

Здравко Ганев 1 Reputation point
2022-06-11T18:54:49.337+00:00

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MobileInput : MonoBehaviour
{
private const float DEADZONE = 100.0f;

public static MobileInput Instance { set; get; }      

private bool tap, swipeLeft, swipeRight, swipeUp, swipeDown;  
private Vector2 swipeDelta, startTouch;  

public bool Tap { get { return tap; } }  
public Vector2 SwipeDelta { get { return swipeDelta;  }  
public bool SwipeLeft { get { return swipeLeft ; } }  
public bool SwipeRight { get { return swipeRight; } }  
public bool SwipeUp { get { return swipeUp; } }  
public bool SwipeDown { get { return swipeDown; } }  

private void Awake()  
{  
    Instance = this;  
}  

private void update()  
{  
    tap = swipeLeft = swipeRight = swipeUp = swipeDown = false;  


    #region Standalone Inputs  
    if (Input.GetMouseButton(0))  
    {  
        tap = true;  
        startTouch = Input.mousePosition;   
    }  
    else if(Input.GetMouseButtonup(0))  
    {  
        startTouch = swipeDelta = Vector2.zero;  
    }  
    #endregion  

    #region Mobile Inputs  
    if (Input.touches.Length != 0)  
    {  
        if (Input.touches[0].phase = TouchPhase.Began)  
        {  
            tap = true;  
            startTouch = Input.mousePosition;  
        }  
        else if (Input.touches[0].phase == TouchPhase.Ended || Input.touches[0].phase == TouchPhase.Canceled)  
        {  
            startTouch = swipeDelta = Vector2.zero;  
        }  
    }  

    #endregion  

    swipeDelta = Vector2.zero;  
    if (startTouch != Vector2.zero)  
    {  
        if (Input.touches.Lenght != 0)  
        {  
            swipeDelta = Input.touches[0].position - startTouch;  
        }  
        else if (Input.GetMouseButtonDown(0))  
        {  
            swipeDelta = (Vector2)Input.mousePosition - startTouch;  
        }  
    }  
  
    if (swipeDelta.magnitude > DEADZONE)  
    {  
        float x = swipeDelta.x;  
        float y = swipeDelta.y;  

        if(Mathf.Abs(x) > mathf.Abs(y))  
        {  
            //left or right  
            if (x < 0)  
                swipeLeft = true;  
            else  
                swipeRight = true;  
        }  
        else  
        {  
            //up or down  
            if (x < 0)  
                swipeDown = true;  
            else  
                swipeUp = true;  
        }  

        startTouch = swipeDelta = Vector2.zero;  
    }  
}  

}
210477-3.png

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.


1 answer

Sort by: Most helpful
  1. Viorel 127K Reputation points
    2022-06-11T18:59:50.77+00:00

    See SwipeDelta.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.