Unity中实现这样的功能,关于按一直住Button时会触发事件,松开button后停止事件

using UnityEngine;
using UnityEngine.EventSystems;
public class OnAnXiaBuSongShou : MonoBehaviour , IPointerUpHandler,IPointerDownHandler
{
public GameObject run_GameObject;
public float speed=10f;
private bool isRun;

public void Move()
{
run_GameObject.transform.position += run_GameObject.transform.forward * speed*Time.deltaTime;
}
// Update is called once per frame
void Update () {
if(isRun)
{
Move();
}
}
public void OnPointerUp(PointerEventData eventData)
{
isRun = false;
}
public void OnPointerDown(PointerEventData eventData)
{
isRun = true;
}
}

推荐阅读更多精彩内容