private void Move()
    {
        //Verificamos que el numero de waypoints no sea mayor a los totales en el escenario sino destruimos al enemigo
        if (waypointIndex <= waypointTransforms.Count - 1)
        {
            Vector3 targetPosition = waypointTransforms[waypointIndex].transform.position;
            float   moveThisFrame  = _waveConfiguration.GetMoveSpeed() * Time.deltaTime;
            transform.position = Vector2.MoveTowards(transform.position, targetPosition, moveThisFrame); //Movemos el enemigo a la posicion de nuestros waytransfomr

            if (transform.position == targetPosition)
            {
                waypointIndex++;
            }
        }
        else
        {
            Destroy(gameObject);
        }
    }
示例#2
0
    private void Move()
    {
        if (waypointIndex <= waypoints.Count - 1)
        {
            // Get target position and set movement
            var targetPosition    = waypoints[waypointIndex].transform.position;
            var movementThisFrame = waveConfiguration.GetMoveSpeed() * Time.deltaTime;

            // Set new position
            transform.position = Vector2.MoveTowards(transform.position, targetPosition, movementThisFrame);

            // Increase waypointIndex variable
            if (transform.position == targetPosition)
            {
                waypointIndex++;
            }
        }
        else
        {
            // Destroy the path after it ran
            Destroy(gameObject);
        }
    }