Hello, i have a simple code that basically create an object when i press a mouse button, and destroy the object when i release the mouse button.
it work fine until i click on and release the mouse button very fast, then from time to time the object won’t get destroyed.
this is the code:
void Update ()
{
CallForMovement();
}
void CallForMovement()
{
if(Input.GetMouseButtonDown(2) || Input.GetMouseButtonUp(2)) // Create the object
{
if (Input.GetMouseButtonDown(2))
{
Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit);
cameraParentObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
cameraParentObject.transform.position = hit.point;
transform.parent = cameraParentObject.transform;
}
if (Input.GetMouseButtonUp(2)) // Destroy the object
{
transform.parent = null;
Destroy(cameraParentObject);
}
}
}