Esempio n. 1
0
    void OnDestroy()
    {
        //being paranoid again, make absolute sure you are removed from the grids before being destroyed
        //but this shouldn't really ever get called
        if (GridManagement.IsInGrid(gameObject))
        {
            GridManagement.ClearPosition(GridManagement.GetPositionOfObject(gameObject), solid);
        }


        GridMovementGeneral.StopCoroutines(gameObject); //and stop any movement coroutines that are on it
    }
    /// <summary>
    /// moves thingtomove to positiontomoveto over a duration of timetomove seconds
    /// </summary>
    /// <param name="thingToMove">the object the movement is applied to</param>
    /// <param name="positionToMoveTo">the position to move it to</param>
    /// <param name="timeToMove">how long to take in seconds</param>
    /// <returns></returns>
    static IEnumerator PositionLerp(GameObject thingToMove, Vector3 positionToMoveTo)
    {
        float currentTime = 0;

        Vector3 originalPosish = thingToMove.transform.position;

        while (true)
        {
            currentTime += Time.deltaTime;
            thingToMove.transform.position = Vector3.Lerp(originalPosish, positionToMoveTo, currentTime / instance.timeForLerps);
            if (currentTime / instance.timeForLerps <= 1f)
            {
                yield return(new WaitForEndOfFrame());
            }
            else
            {
                //snap it at the end to it's grid pos
                thingToMove.transform.position = GridManagement.GetPositionOfObject(thingToMove);
                //print("finished Rotation");
                break;
            }
        }
    }