zl程序教程

您现在的位置是:首页 >  工具

当前栏目

长按实现安卓端下载图片和安装包

安装包下载 实现 图片
2023-09-27 14:27:29 时间

①长按按钮保存图片至安卓手机相册

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LongPress : MonoBehaviour
{
    //设置变量记录触摸时间与bool触摸
    private float touchTime;
    private bool newTouch = false;
    void Update () {
        //判断是否单击,单击则进入if分支
        if (Input.GetMouseButton (0)){
            //设置一条射线
            Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
            //设置接收射线的返回值
            RaycastHit hitInfo;
            //如果射线碰到物体,返回为真,进入if分支
            if (Physics.Raycast (ray, out hitInfo)) {
                //当一根手指触摸,则进入if分支
                if (Input.touchCount == 1 ) {
                    //记录触摸
                    Touch touch = Input.GetTouch (0);
                    //如果触摸刚开始,则进入if分支
                    if (t