我在这堂课中得到#endregoin diretive expected
:
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, swipeLeft, swipeRight, swipeUp, swipeUp, swipeDown;
private Vector2 swipeDelta, startTouch;
public bool Tap { get { return tap; } }
public Vector2 SwipeDelta { get { return swipeDelta; } }
public Vector2 SwipeLeft { get { return swipeLeft; } }
public Vector2 SwipeRight { get { return swipeRight; } }
public Vector2 SwipeUp { get { return swipeUp; } }
public Vector2 SwipeDown { get { return swipeDown; } }
private void Awake()
{
Instance = this;
}
private void Update()
{
//reseting all the bool
tap = swipeLeft = swipeRight = swipeDown = swipeUp = false;
//lets check input
#region Standalone Inputs
if (Input.GetMouseButtonDown(0))
{
tap = true;
startTouch = Input.mousePosition;
}
else if (Input.GetMouseBottonUp(0))
{
startTouch = swipeDelta = Vector2.zero;
}
#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
//Calculate
swipeDelta = Vector2.zero;
if (startTouch != Vector2.zero)
{
//let's check
if (Input.touches.Length != 0)
{
swipeDelta = Input.touches[0].position - startTouch;
}
//lets check standalone
else if (Input.GetMouseButton(0))
{
swipeDelta = (Vector2)Input.mousePosition - startTouch;
}
}
//Check dead zone
if (swipeDelta.magnitude > DEADZONE)
{
// this is a confirmed swip
float x = swipeDelta.x;
float y = swipeDelta.y;
if (Mathf.Abs(x) > Mathf.Abs(y))
{
//left
if (x < 0)
swipeLeft = true;
else
swipeRight = true;
}
else
{
//up or down
if (y < 0)
swipeDown = true;
else
swipeUp = true;
}
startTouch = swipeDelta = Vector2.zero;
}
}
}
答案 0 :(得分:2)
您的#region Standalone Inputs
在代码中缺少#endregion
。