void ClearRespawnOrDespawnProgress()
 {
     if (DespawningCorout != null)
     {
         StopCoroutine(DespawningCorout);
     }
     if (RespawningCorout != null)
     {
         StopCoroutine(RespawningCorout);
     }
     myState = RespawnObjectState.Valid;
 }
        IEnumerator Despawn(float delayDespawn, float respawnWaitTime)
        {
            yield return(new WaitForSeconds(delayDespawn));

            disabledGrab = myself.isGrabbable;
            disabledUse  = myself.isUsable;
            myself.transform.position   = Vector3.one * 1000;
            myself.transform.localScale = Vector3.zero;
            myself.transform.rotation   = Quaternion.identity;

            yield return(new WaitForSeconds(respawnWaitTime));

            myState = RespawnObjectState.Waiting;
            StartRespawn();
        }
        public void StartDespawn(float delayDespawn, float respawnWaitTime)
        {
            ClearRespawnOrDespawnProgress();
            if (myState == RespawnObjectState.Valid)
            {
                if (myself.IsGrabbed())
                {
                    myself.Ungrabbed(myself.GetGrabbingObject());
                }
                myState = RespawnObjectState.Despawning;
                //Shrink myself out of existence
                //Display a POOF particle.

                DespawningCorout = StartCoroutine(Despawn(delayDespawn, respawnWaitTime));
            }
        }
        IEnumerator Respawn()
        {
            if (myState == RespawnObjectState.Waiting)
            {
                myState = RespawnObjectState.Respawning;

                //Store previous state
                disabledGrab = myself.isGrabbable;
                disabledUse  = myself.isUsable;

                if (myRB != null)
                {
                    myRB.velocity        = Vector3.zero;
                    myRB.angularVelocity = Vector3.zero;
                    myRB.useGravity      = false;
                }

                //Turn off our interaction types.
                myself.isGrabbable = false;
                myself.isUsable    = false;

                //Result is to lock self while we grow.
                myself.transform.localRotation = resetRotation;
                myself.transform.position      = resetPosition;
                //Grow over N frames.
                for (int i = 0; i < FramesToGrow; i++)
                {
                    float percentage = (float)i / FramesToGrow;
                    //myself.transform.position = resetPosition - Vector3.up * resetScale.y / 2 * ((float)i) / frameCount;
                    myself.transform.localScale = Vector3.Lerp(Vector3.zero, resetScale, percentage);
                    //myself.transform.position = resetPosition - (Vector3.up * resetScale.y / 3) + (Vector3.up * resetScale.y) * percentage;
                    yield return(null);
                }
                //Relocate myself, rescale myself, set rotation
                myself.transform.position   = resetPosition;
                myself.transform.localScale = resetScale;

                RestoreInteractions(disabledGrab, disabledUse);
                myState = RespawnObjectState.Valid;

                if (myRB != null)
                {
                    myRB.useGravity = true;
                }
            }
        }