Created
August 20, 2021 02:06
-
-
Save cacapon/480857797ae130999fcb7ad049060ec7 to your computer and use it in GitHub Desktop.
ブログ用 各マスを感知するためのスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.EventSystems; | |
using System; | |
public class StageEreaTouchEvent : MonoBehaviour,IPointerDownHandler,IPointerUpHandler | |
{ | |
[SerializeField] private PieceCommand pieceCommand; | |
[SerializeField] private float taptime; | |
private Vector2Int pos; | |
private float begintaptime = 0f; | |
private bool istaped = false; | |
private void Awake() { | |
pos = new Vector2Int(); | |
pos.y = Convert.ToInt32(gameObject.name.Substring(0,1)); | |
pos.x = Convert.ToInt32(gameObject.name.Substring(1,1)); | |
} | |
private void Update() { | |
if( istaped && Time.time - begintaptime >= taptime) | |
{ | |
pieceCommand.Holdon(pos); | |
istaped = false; | |
} | |
} | |
public void OnPointerDown(PointerEventData eventData) | |
{ | |
istaped =true; | |
begintaptime = Time.time; | |
} | |
public void OnPointerUp(PointerEventData eventData) | |
{ | |
istaped = false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment