Basic idea:
Crate prefab spawns.
If you double click on the crate, it instantiates a larger version of that, a sort of ‘zoom in’ on it, to show details.
If you then click outside of the panel, it destroys the instantiated clone, as well as hiding the UI panel that has the other details on it.
Currently this destroys both the clone and the original, which isn't what I want, I just want to destroy that clone. if (Input.GetMouseButtonDown(0))
{
float timeSinceLastClick = Time.time - lastClickTime;
Ray mouseRay = GenerateMouseRay();
RaycastHit hit;
if (Physics.Raycast(mouseRay.origin, mouseRay.direction, out hit))
{
if (hit.transform.tag == "crate")
{
if (timeSinceLastClick < clickThreshold)
{
doubleClick = true;
Debug.Log("Double click");
Debug.Log(timeSinceLastClick);
crateHighlighted = true;
currentCrate = hit.transform.gameObject;
ToggleHighlight(currentCrate);
Time.timeScale = 0;
}
lastClickTime = Time.time;
//currentCrate set to gameObject that was hit
currentCrate = hit.transform.gameObject;
}
else
{
if (crateHighlighted)
{
ResumeTime();
}
}
}
}
void ToggleHighlight(GameObject selectedPackage)
{
highlightedCrateTemp = selectedPackage;
Debug.Log(highlightedCrateTemp.GetComponent<Crate>().itemName);
GameObject highlightedPackage = Instantiate(highlightedCrateTemp, highlightedCratePos, highlightedCrateTemp.transform.rotation);
Destroy(highlightedPackage.GetComponent<Rigidbody>());
uiManager.DisplayHighlightedDetails(highlightedCrateTemp);
}
void ResumeTime()
{
Time.timeScale = 1;
uiManager.highlightedObjectDetails.SetActive(false);
highlightedCrateTemp.SetActive(false);
Destroy(highlightedCrateTemp);
}