private void Update()
    {
        if (isTeleporterActive)
        {
            PlatformGameplay gameplayComponent = GetComponent <PlatformGameplay>();
            float            lerpValue         = (gameplayComponent.delayBetweenMovements - gameplayComponent.DelayTimer) / gameplayComponent.delayBetweenMovements;
            meshRenderer.material.SetColor("_EmissionColor", Color.Lerp(startColor, Color.red, lerpValue));
            if (lerpValue >= 1.0f)
            {
                isTeleporterActive = false;
                if (teleportToMinigame)
                {
                    LoadMinigame();
                }
                else
                {
                    Invoke("ResetPlatform", 0.1f); // WARNING! Should be call in any cases if we dont load scenes
                }
            }
        }

        if (teleportToMinigame)
        {
            if (lerpValueAnim < 1.0f)
            {
                lerpValueAnim     += Time.deltaTime;
                transform.position = Vector3.Lerp(originPosition, endPosition, lerpValueAnim);
            }
            else
            {
                GetComponent <PlatformGameplay>().isATeleporter = true;
                isTeleporterActive = true;
            }
        }
    }
Exemple #2
0
    void ActivateTrap()
    {
        gameplay = GetComponent <PlatformGameplay>();
        Material mat = GetComponentInChildren <MeshRenderer>().material;

        mat.SetColor("_EmissionColor", Color.red);

        if (gameplay == null)
        {
            Debug.LogWarning("Platform gameplay component is null and shouldn't");
            return;
        }
        TrapType trapRand;

        // si la platforme est générée par le platformiste
        if (!isLevelDesignPlatform)
        {
            trapRand = (TrapType)Random.Range(0, (int)TrapType.Size);
            List <TrapType> usedIndex  = new List <TrapType>();
            int             nbAttempts = 0;

            while (!TrapViabilityCheck(trapRand) || nbAttempts == 10)
            {
                usedIndex.Add(trapRand);
                bool isInList = true;
                while (isInList)
                {
                    trapRand = (TrapType)Random.Range(0, (int)TrapType.Size);
                    foreach (TrapType checkedType in usedIndex)
                    {
                        if (checkedType != trapRand)
                        {
                            isInList = false;
                        }
                    }
                }
                nbAttempts++;
            }

            if (nbAttempts == 10)
            {
                trapRand = TrapType.Flip;
            }
        }
        else // si la platforme a été posée en LevelDesign
        {
            trapRand = trapType;
            StartCoroutine(ResetTrap());
        }

        switch (trapRand)
        {
        case TrapType.MoveHorizontal:
            MoveHorizontal();
            break;

        case TrapType.MoveBackward:
            MoveBackward();
            break;

        case TrapType.MoveDown:
            MoveDown();
            break;

        case TrapType.RotateAroundY:
            RotateAroundY();
            break;

        case TrapType.Flip:
            Flip();
            break;
        }

        isTrapEnabled = true;
    }