Unity长按屏幕计时器

这篇博客详细介绍了如何在Unity中利用Input系统和触摸事件实现长按屏幕的计时器功能,适用于移动端游戏开发。通过监听触摸开始和结束事件,计算两者之间的时间差,从而达到长按计时的效果。
摘要由CSDN通过智能技术生成
using UnityEngine;
using System.Collections;

public class RotateAndMove : MonoBehaviour {
    private float time;
    private bool isRotating=false ;
    private Vector3 m_endpos;
    public  float rotateSpeed=-2;//旋转速度
    public  float moveSpeed=1;//旋转速度
    // Use this for initialization
    void Start () {
        
    }
    
    // Update is called once per frame
    void Update () {
        if (Input.touchCount == 1) {
            time+=Time.deltaTime;//当只有一个手指按屏幕时,开始计时
            //print ("只有一个手指按屏幕时,开始计时");
            if (Input.touches[0].phase==TouchPhase.Ended&&Input.touches[0].phase!=TouchPhase.Canceled){
                //canceled的意思是系统取消跟踪触摸,如果用户把屏幕放到他的脸上uop超过五个触摸点时的状态
                m_endpos=Input.touches[0].position;
                tim
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值