Esempio n. 1
0
    public void Move()
    {
        if (NewPathGhostScript.GhostPathPoints.Count > 0 && PlayerState == States.ReadyToMove)
        {
            _endPosition = NewPathGhostScript.GetPathPoint();
            PlayerState  = States.Moving;
        }

        if (PlayerState == States.Moving)
        {
            transform.position = LerpMoveTo(_startPosition, _endPosition, TimeToReachNextTile);
            _time += Time.deltaTime;

            if (_time >= TimeToReachNextTile)
            {
                _time              = 0;
                PlayerState        = States.ReadyToMove;
                transform.position = _endPosition;
                _startPosition     = _endPosition;
            }
        }
    }
    IEnumerator NewPositionDelay()
    {
        Vector3 endPosition;
        float   x = 0;
        float   z = 0;

        yield return(new WaitForSeconds(0.2f));

        newPosition = Player.transform.position;
        Debug.LogError("newPosition = " + newPosition);



        if (oldPosition == newPosition)
        {
            StartCoroutine(LaterUnblockAbortMove());
            yield break;
        }
        else if (oldPosition.x == newPosition.x)
        {
            if ((oldPosition.z - newPosition.z) > 0)
            {
                z = Mathf.Floor(newPosition.z);
            }
            else
            {
                z = Mathf.Ceil(newPosition.z);
            }
            x = oldPosition.x;
        }
        else if (oldPosition.z == newPosition.z)
        {
            if ((oldPosition.x - newPosition.x) > 0)
            {
                x = Mathf.Floor(newPosition.x);
            }
            else
            {
                x = Mathf.Ceil(newPosition.x);
            }
            z = oldPosition.z;
        }
        endPosition = new Vector3(x, 0, z);

        Player.GetComponent <NewPlayerController>()._startPosition = newPosition;
        Player.GetComponent <NewPlayerController>()._endPosition   = endPosition;

        PlayerGhost.GetComponent <PlayerGhostScript>()._startPosition = endPosition;
        PlayerGhost.GetComponent <PlayerGhostScript>()._endPosition   = endPosition;

        NewPathScript.PreviousPoint           = endPosition;
        NewPathGhostScript.GhostPreviousPoint = endPosition;
        PlayerGhost.transform.position        = endPosition;

        NewPathScript.ClearPathPoints();
        NewPathGhostScript.ClearPathPoints();
        GameObject[] PathPoints = GameObject.FindGameObjectsWithTag("Path");
        foreach (var e in PathPoints)
        {
            Destroy(e);
        }
        StartCoroutine(LaterUnblockAbortMove());
    }