需求模拟激光枪
按下一直会生成特效,松开时特效消失
using UnityEngine; using UnityEngine.EventSystems;
public class buttonEvent : MonoBehaviour,IPointerDownHandler,IPointerUpHandler {
public GameObject texiao;
public void OnPointerDown(PointerEventData eventData)///按下按钮时执行的一个方法 { texiao.GetComponent<fire>().go.SetActive(true);
} public void OnPointerUp(PointerEventData eventData)///松开按钮时执行方法 { texiao.GetComponent<fire>().go.SetActive(false); }
}