Ejemplo n.º 1
0
    void Update()
    {
        var distanceEnd = Vector3.Distance(transform.position, LastWaypointPos);

        if (distanceEnd <= 0.5f)
        {
            GameOver();
        }

        Agent.speed = Speed;

        //Switch waypoints.
        if (Moving)
        {
            float Distance = Vector3.Distance(transform.position, Agent.destination);
            if (Distance <= 0f)
            {
                destination       = Waypoints[Index++].transform.position;
                Agent.destination = destination;
            }
        }

        //Check Distance previous balls.
        var   PrevBallPos          = ballSpawner.CheckPreviousBall(this).transform.position;
        float DistancePreviousBall = Vector3.Distance(transform.position, PrevBallPos);

        if (DistancePreviousBall > 1 && !SpeedingUp)
        {
            MoveBack();
        }
        else if (DistancePreviousBall < 1 && !SpeedingUp && !Moving)
        {
            MoveAgain();
        }
    }