类似于地铁跑酷往上滑起跳
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AndroidMove : MonoBehaviour
{
Vector2 startTouchPos;
void Start ()
{
startTouchPos = Vector2.zero;
}
void Update ()
{
int touchCount = Input.touchCount;
if (touchCount > 0)
{
for (int i = 0; i < touchCount; i++)
{
Touch touch = Input.GetTouch(i);
if (touch.phase.Equals(TouchPhase.Began))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray,out hit))
{
Debug.Log(hit.transform.name);
startTouchPos = touch.position;
}
}
else if (touch.phase.Equals(TouchPhase.Moved))
{
if (touch.position.y-startTouchPos.y > 0)
{
Debug.Log("跳");
}
}
else if (touch.phase.Equals(TouchPhase.Ended))
{
startTouchPos = Vector2.zero;
}
}
}
}
}
网友评论