I understand the problem is there a way around it though?
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour
{
public float MineSpeed = 1;
public GameObject ItemHit;
public Item ItemScript;
void Start ()
{
}
void Update ()
{
StartCoroutine(playerHit());
}
IEnumerator playerHit()
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, 50))
{
ItemHit = hit.transform.gameObject;
ItemScript = ItemHit.GetComponent<Item>();
if (Input.GetMouseButton(0))
{
yield return new WaitForSeconds(ItemScript.ItemMiningSpeed * MineSpeed);
if (Input.GetMouseButton(0))
{
Destroy(ItemScript.ThisItem);
}
}
}
}
}
After waiting and the object is destroyed every object I look at after this while holding mouse down is destroyed instantly.