Esempio n. 1
0
    public void ToggleWormhole(InputAction.CallbackContext context)
    {
        if (!IsPlayerActive)
        {
            return;
        }

        if (context.phase != InputActionPhase.Canceled)
        {
            return;
        }

        if (ActiveWormhole != null && ActiveWormhole.IsActive)
        {
            ActiveWormhole.Disable();
            ActiveWormhole = null;
        }
        else
        {
            var mousePos        = Mouse.current.position.ReadValue();
            var currentPosition = Camera.main.ScreenToWorldPoint(new Vector3(mousePos.x, mousePos.y));

            var distanceFromPlayer = Mathf.Abs(Vector2.Distance(currentPosition, player.transform.position));
            if (distanceFromPlayer <= wormholeWidth / 2 + minDistanceOffsetFromPlayer)
            {
                return;
            }

            CreateWormHole(currentPosition);

            WormholesUsed++;
        }
    }
Esempio n. 2
0
    private void OnPlayerFinish()
    {
        if (!IsPlayerActive)
        {
            return;
        }

        if (ActiveWormhole != null && ActiveWormhole.IsActive)
        {
            ActiveWormhole.Disable();
            ActiveWormhole = null;
        }

        CreateWormHole(finishGameObject.transform.position);
        IsPlayerActive = false;

        scores[currentLevelIndex] = WormholesUsed;
        scoreCardManager.UpdateScores(scores, currentLevelIndex + 1 >= scores.Count);
    }
Esempio n. 3
0
    private void CreateWormHole(Vector3 position)
    {
        if (ActiveWormhole != null && ActiveWormhole.IsActive)
        {
            ActiveWormhole.Disable();
            ActiveWormhole = null;
        }

        var newWormhole = wormholePool?.FirstOrDefault(x => !x.isActiveAndEnabled);

        if (newWormhole == null)
        {
            newWormhole = Instantiate(wormholePrefab).GetComponent <Wormhole>();
            newWormhole.transform.localScale = Vector3.one * wormholeWidth;
            wormholePool.Add(newWormhole);
        }

        newWormhole.Activate(position);
        ActiveWormhole = newWormhole;
    }