LeanTouch控制移动 Lean_Touch控制移动
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
豆饼怎么炒好吃using Lean.Touch;
public class Lean_Touch: MonoBehaviour
{
public float speed=100;//定义速度上下
private Rigidbody _rig;//定义移动刚体
private Renderer _render;//定义材质渲染
private float offts = 0;//定义渲染变量
/
水煮饭/初始化
public void Awake()
{
//得到组件
_rig = GetComponent<Rigidbody>();
_render = GetComponent<Renderer>();
}
//开启启动
protected virtual void OnEnable()
{
//监听加事件
盛组词多音字
LeanTouch.OnGesture += OnGesture;
}
//关闭禁⽤
protected virtual void OnDisable()
{
//监听去事件
LeanTouch.OnGesture -= OnGesture;
}
车厘子的英文//List<LeanFinger> fingers参数的⽅法
public void OnGesture(List<LeanFinger> fingers)
{
/
/判断上划
if (LeanGesture.GetScaledDelta(fingers).x > 0 )
{
//材质球偏移量
offts += 0.1f;
_render.material.mainTextureOfft = new Vector2(offts, 0);
//给物体x加⼒
shut过去式_rig.AddForce(new Vector3(speed, 0, 0), ForceMode.Force);
}
//判断下划
if (LeanGesture.GetScaledDelta(fingers).x < 0 )
{
//材质球偏移量
木桥村offts -= 0.1f;
_render.material.mainTextureOfft = new Vector2(offts, 0);
//给物体x加反向⼒
_rig.AddForce(new Vector3(-speed, 0, 0), ForceMode.Force);我来网
}
//判断左划
if (LeanGesture.GetScaledDelta(fingers).y > 0 )
{
//给物体x加反向⼒
崔九堂前几度闻上一句
_rig.AddForce(new Vector3(0, 0, speed), ForceMode.Force);
}
//判断右划
if (LeanGesture.GetScaledDelta(fingers).y < 0 )
{
//给物体x加反向⼒
_rig.AddForce(new Vector3(0, 0, -speed), ForceMode.Force);
}
//根据滑动⽅向给物体选择⾯朝⽅向
Vector3 movePosition = new Vector3(LeanGesture.GetScaledDelta(fingers).x, 0, LeanGesture.GetScaledDelta(fingers).y);
Vector3 dir = transform.position + movePosition;
transform.LookAt(dir);
}
}
注:此移动⽅式是在LeanTouch插件下进⾏的移动旋转、移动加⼒⽅式根据需要调节、ForceMode.Force:给物体添加⼀个持续的⼒并使⽤其质量、ForceMode.Acceleration:给物体添加⼀个持续的加速度,但是忽略其质量、 ForceMode.Impul:给物体添加⼀个瞬间的⼒并使⽤其质量、ForceMode.VelocityChange:给物体添加⼀个瞬间的加速度,但是忽略其质量。