63 lines
1.6 KiB
C#
63 lines
1.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
|
|
public class ClickArea : MonoBehaviour,IPointerDownHandler,IPointerUpHandler,IPointerExitHandler
|
|
{
|
|
public Buildings buildings;
|
|
public bool corotineStart = false;
|
|
private IEnumerator DR;
|
|
private void Start()
|
|
{
|
|
buildings = transform.parent.GetComponent<Buildings>();
|
|
}
|
|
public void OnPointerDown(PointerEventData eventData)
|
|
{
|
|
if (!BuildingsManager.Instance.isDragActive)
|
|
{
|
|
buildings.AddResources_Click();
|
|
}
|
|
else
|
|
{
|
|
if (!corotineStart)
|
|
{
|
|
buildings.AddResources_Click();
|
|
DR = DragToAddRes();
|
|
StartCoroutine(DR);
|
|
corotineStart = true;
|
|
}
|
|
}
|
|
}
|
|
public void OnPointerUp(PointerEventData eventData)
|
|
{
|
|
if (BuildingsManager.Instance.isDragActive && corotineStart)
|
|
{
|
|
StopCoroutine(DR);
|
|
corotineStart = false;
|
|
}
|
|
}
|
|
public void OnPointerExit(PointerEventData eventData)
|
|
{
|
|
if (BuildingsManager.Instance.isDragActive && corotineStart)
|
|
{
|
|
StopCoroutine(DR);
|
|
corotineStart = false;
|
|
}
|
|
}
|
|
private IEnumerator DragToAddRes()
|
|
{
|
|
int x = 0;
|
|
while (true)
|
|
{
|
|
if (x >= 1)
|
|
{
|
|
buildings.AddResources_Click();
|
|
x = 0;
|
|
}
|
|
x++;
|
|
yield return new WaitForSeconds(0.2f);
|
|
}
|
|
}
|
|
}
|