using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using DG.Tweening;
using System;
using UnityEngine.EventSystems;
public class jarodInputController : MonoBehaviour/* , IDragHandler*/
{
// public RectTransform yigong;
private float fingerActionSensitivity = Screen.width * 0.05f; //手指动作的敏感度,这里设定为 二十分之一的屏幕宽度.
//
private float fingerBeginX;
private float fingerBeginY;
private float fingerCurrentX;
private float fingerCurrentY;
private float fingerSegmentX;
private float fingerSegmentY;
//
private int fingerTouchState;
//
private int FINGER_STATE_NULL = 0;
private int FINGER_STATE_TOUCH = 1;
private int FINGER_STATE_ADD = 2;
public Toggle shengcan;
public Toggle shigong;
public bool IsGongyi=false;
public bool IsRight = false;
public TestButton testButton;
void Start()
{
fingerActionSensitivity = Screen.width * 0.05f;
fingerBeginX = 0;
fingerBeginY = 0;
fingerCurrentX = 0;
fingerCurrentY = 0;
fingerSegmentX = 0;
fingerSegmentY = 0;
fingerTouchState = FINGER_STATE_NULL;
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Mouse0))
{
if (fingerTouchState == FINGER_STATE_NULL)
{
fingerTouchState = FINGER_STATE_TOUCH;
fingerBeginX = Input.mousePosition.x;
fingerBeginY = Input.mousePosition.y;
}
}
if (fingerTouchState == FINGER_STATE_TOUCH)
{
fingerCurrentX = Input.mousePosition.x;
fingerCurrentY = Input.mousePosition.y;
fingerSegmentX = fingerCurrentX - fingerBeginX;
fingerSegmentY = fingerCurrentY - fingerBeginY;
}
if (fingerTouchState == FINGER_STATE_TOUCH)
{
float fingerDistance = fingerSegmentX * fingerSegmentX + fingerSegmentY * fingerSegmentY;
if (fingerDistance > (fingerActionSensitivity * fingerActionSensitivity))
{
toAddFingerAction();
}
}
if (Input.GetKeyUp(KeyCode.Mouse0))
{
fingerTouchState = FINGER_STATE_NULL;
}
}
private void toAddFingerAction()
{
fingerTouchState = FINGER_STATE_ADD;
if (Mathf.Abs(fingerSegmentX) > Mathf.Abs(fingerSegmentY))
{
fingerSegmentY = 0;
}
else
{
fingerSegmentX = 0;
}
if (fingerSegmentX == 0)
{
if (fingerSegmentY > 0)
{
//Debug.Log("up");
}
else
{
//Debug.Log("down");
}
}
else if (fingerSegmentY == 0)
{
if (fingerSegmentX > 0)
{
Debug.Log("right");
}
else
{
Debug.Log("left");
}
}
}
}
unity 上下左右滑动屏幕
原创
©著作权归作者所有:来自51CTO博客作者诗远__的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:unity实现卡牌翻动效果
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
有趣的CSS - 按钮文字上下滑动
使用css实现按钮内两个元素上下滑动过渡的交互动画。
css html 按钮动效 ui -
有趣的css - 颜色滑动切换按钮
当鼠标悬浮在按钮上方时,按钮背景色从左往右滑动变化一个变化切换按钮。
css动画 动效设计 交互设计 用户体验 按钮 -
Java服务优雅上下线
Java服务优雅上下线
ide JVM sed