using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using UnityEngine.EventSystems;
public class MoveDown : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IPointerClickHandler
{
public GameObject go;
//要移动的物体
private float delay = 0.01f;
//延迟时间,时间越小,运动越连贯平稳,越大越顿
private bool isDown = false;
//按钮是否被按下
private float lastIsDownTime;
//按钮最后一次被按下的时间
// Update is called once per frame
void Update()
{
//如果按钮是被按下状态
if (isDown)
{
// 当前时间 - 按钮最后一
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using UnityEngine.EventSystems;
public class MoveDown : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IPointerClickHandler
{
public GameObject go;
//要移动的物体
private float delay = 0.01f;
//延迟时间,时间越小,运动越连贯平稳,越大越顿
private bool isDown = false;
//按钮是否被按下
private float lastIsDownTime;
//按钮最后一次被按下的时间
// Update is called once per frame
void Update()
{
//如果按钮是被按下状态
if (isDown)
{
// 当前时间 - 按钮最后一

本文介绍了一个Unity脚本,实现点击和长按按钮控制游戏物体沿Y轴向下平滑移动。通过实现IPointerDownHandler、IPointerUpHandler和IPointerClickHandler接口,监听按钮事件。Update方法中根据延迟时间和按钮状态决定物体移动,OnPointerClick、OnPointerDown和OnPointerUp处理点击、按住和释放按钮的逻辑。
最低0.47元/天 解锁文章
1401

被折叠的 条评论
为什么被折叠?



