예제 #1
0
    public void AddPlayerTween()
    {
        if (activeTween == null)
        {
            if (pos.x == 6 && pos.y == -1) // Move Down
            {
                activeTween = new PlayerTween(player.transform, player.transform.position, new Vector3(6.0f, -5.0f, 0.0f), Time.time, 1.5f);
            }

            if (pos.x == 6 && pos.y == -5) // Move Left
            {
                activeTween = new PlayerTween(player.transform, player.transform.position, new Vector3(1.0f, -5.0f, 0.0f), Time.time, 1.5f);
            }

            if (pos.x == 1 && pos.y == -5) // Move Up
            {
                activeTween = new PlayerTween(player.transform, player.transform.position, new Vector3(1.0f, -1.0f, 0.0f), Time.time, 1.5f);
            }

            if (pos.x == 1 && pos.y == -1) // Move Right
            {
                activeTween = new PlayerTween(player.transform, player.transform.position, new Vector3(6.0f, -1.0f, 0.0f), Time.time, 1.5f);
            }
        }
    }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        AddPlayerTween();
        if (activeTween != null)
        {
            checkDirection(); // Controls animator

            // Cubic easing-in interpolation
            float time         = (Time.time - activeTween.StartTime) / activeTween.Duration;
            float timeFraction = time * time * time;

            // Distance between current object's position and the EndPos not "StartPos"
            float dist = Vector3.Distance(activeTween.Target.position, activeTween.EndPos);

            if (dist > 0.1f)
            {
                activeTween.Target.transform.position = Vector3.Lerp(activeTween.StartPos, activeTween.EndPos, timeFraction);
            }
            if (dist < 0.1f)
            {
                activeTween.Target.position = activeTween.EndPos;
                activeTween = null;
            }
        }

        pos = player.transform.position; // Get position of player
    }