Beispiel #1
0
    private void Update()
    {
        Debug.Log(_isOptionOrPlayOpen);

        if (_isOptionOrPlayOpen)
        {
            _animator.SetBool("IsSlingshoting", false);
            _myRb.velocity = Vector2.zero;
            _timerPower    = 0;
        }


        if (_playerInput == INPUTSTATE.GivingInput && _mustPlayCastSound)
        {
            _newSoundManagerScript.PlayCharge(int.Parse(gameObject.tag.Substring(gameObject.tag.Length - 1)) - 1);
            _mustPlayCastSound = false;
        }
        else if (_playerInput == INPUTSTATE.None)
        {
            _newSoundManagerScript.StopCharge(int.Parse(gameObject.tag.Substring(gameObject.tag.Length - 1)) - 1);
            _mustPlayCastSound = true;
        }

        if (_menuInformationScript == null || _menuInformationScript.GetVibrationsValue())
        {
            if (powerJauge.fillAmount > vibrationTreshold)
            {
                if (gameObject.tag == "Player1")
                {
                    _playerManagerScript.Vibration(_playerManagerScript._player, 0, 1.0f, vibrationTreshold * 0.5f);
                }
                vibrationTreshold += 0.2f;
            }
            else if (powerJauge.fillAmount == vibrationTreshold)
            {
                if (gameObject.tag == "Player1")
                {
                    _playerManagerScript.Vibration(_playerManagerScript._player, 0, 1.0f, tooMuchPowerTimerMax);
                }
            }
        }
    }
Beispiel #2
0
    // Update is called once per frame
    void Update()
    {
        print("pressA : " + _isPressAHere);
        if (_isOnOptions || _isCharSelecShowing || _isStartGameShowing || _isOnCredits)
        {
            playerEntity.IsInOptionOrCharacterMenu(true);
            _player.StopVibration();
        }
        else
        {
            playerEntity.IsInOptionOrCharacterMenu(false);
        }

        if (_isPressAHere)
        {
            if (!_theMenuHasBegun && _player.GetButtonUp("Push1"))
            {
                startPanel.SetActive(false);
                _theMenuHasBegun = true;
                _isPressAHere    = false;
                textPressA.SetActive(false);
            }
        }
        else
        {
            if (_player.GetButtonUp("Push1"))
            {
                logo.GetComponent <Animator>().Play(0, -1, 1);
            }
        }
        if (_theMenuHasBegun)
        {
            if (!_isOnOptions && !_isCharSelecShowing && !_isStartGameShowing && !_isOnCredits && !_hasOptionOrPlayOpened && !_isOnTutorial && _player.GetButtonDown("BackMenu"))
            {
                timerMenu = 0;
                startPanel.SetActive(true);
                _theMenuHasBegun = false;
            }
            timerMenu += Time.deltaTime;
            //Gère à quel joueur attribué quel action
            float   inputXPlayer1 = -_player.GetAxis("HorizontalJoy1");
            float   inputYPlayer1 = _player.GetAxis("VerticalJoy1");
            Vector2 dirPlayer1    = new Vector2(inputXPlayer1, inputYPlayer1);
            if (dirPlayer1.magnitude < 0.3f)
            {
                dirPlayer1 = Vector2.zero;
            }
            if (!_isStartGameShowing && !_isOnOptions && !_isCharSelecShowing)
            {
                playerEntity.SetInputX(dirPlayer1);
            }

            //gère apparence boutons vibrations
            if (getMenuInfoScript.GetVibrationsValue())
            {
                vibrationOnOff[0].sprite = spritesSelectedOrNot[1];
                vibrationOnOff[1].sprite = spritesSelectedOrNot[0];
            }
            else
            {
                vibrationOnOff[0].sprite = spritesSelectedOrNot[0];
                vibrationOnOff[1].sprite = spritesSelectedOrNot[1];
            }

            //permet de gérer la surbrillance des boutons de sélections du mode de mouvement
            //selon le booléen du joueur
            #region Affichage Mode Déplacement
            if (getMenuInfoScript.getPlayerMouvementMode()[0])
            {
                mouvementImageP1[0].sprite = spriteSelecOrNoP1[1];
                mouvementImageP1[1].sprite = spriteSelecOrNoP1[2];
            }
            else
            {
                mouvementImageP1[0].sprite = spriteSelecOrNoP1[0];
                mouvementImageP1[1].sprite = spriteSelecOrNoP1[3];
            }
            if (getMenuInfoScript.getPlayerMouvementMode()[1])
            {
                mouvementImageP2[0].sprite = spriteSelecOrNoP2[1];
                mouvementImageP2[1].sprite = spriteSelecOrNoP2[2];
            }
            else
            {
                mouvementImageP2[0].sprite = spriteSelecOrNoP2[0];
                mouvementImageP2[1].sprite = spriteSelecOrNoP2[3];
            }
            if (getMenuInfoScript.numbersOfPlayers >= 3)
            {
                if (getMenuInfoScript.getPlayerMouvementMode()[2])
                {
                    mouvementImageP3[0].sprite = spriteSelecOrNoP3[1];
                    mouvementImageP3[1].sprite = spriteSelecOrNoP3[2];
                }
                else
                {
                    mouvementImageP3[0].sprite = spriteSelecOrNoP3[0];
                    mouvementImageP3[1].sprite = spriteSelecOrNoP3[3];
                }
            }
            if (getMenuInfoScript.numbersOfPlayers == 4)
            {
                if (getMenuInfoScript.getPlayerMouvementMode()[3])
                {
                    mouvementImageP4[0].sprite = spriteSelecOrNoP4[1];
                    mouvementImageP4[1].sprite = spriteSelecOrNoP4[2];
                }
                else
                {
                    mouvementImageP4[0].sprite = spriteSelecOrNoP4[0];
                    mouvementImageP4[1].sprite = spriteSelecOrNoP4[3];
                }
            }
            #endregion

            //Gère à quel joueur attribué quel action

            if (playerEntity.currentFace == 0 && _player.GetButtonUp("Push1") && !_isStartGameShowing && timerMenu >= 0.2 && !_isOnTutorial)
            {
                ShowSelectionChar();
            }
            else if (playerEntity.currentFace == 1 && _player.GetButton("Push1"))
            {
                ExitGame();
            }
            else if (playerEntity.currentFace == 2 && _player.GetButton("Push1"))
            {
                Options();
                _hasOptionOrPlayOpened = true;
            }
            else if (playerEntity.currentFace == 3 && _player.GetButton("Push1"))
            {
                Credits();
                _hasOptionOrPlayOpened = true;
            }

            if (_isCharSelecShowing && _player.GetButtonUp("BackMenu"))
            {
                playerEntity.enabled = true;
                selecPanel.SetActive(false);
                _isCharSelecShowing    = false;
                _hasOptionOrPlayOpened = false;
                _secondPlayerIsHere    = false;
                _thirdPlayerIsHere     = false;
                _fourthPlayerIsHere    = false;
                _isPOneReady           = false;
                _isPTwoReady           = false;
                _isPThreeReady         = false;
                _isPFourReady          = false;
            }
            if (_isOnTutorial && _player.GetButtonUp("BackMenu"))
            {
                tutorialPanel.SetActive(false);
                _isOnTutorial = false;
            }

            if (_isOnCredits && _player.GetButtonUp("BackMenu"))
            {
                creditsPanel.SetActive(false);
                _isOnCredits           = false;
                _hasOptionOrPlayOpened = false;
            }

            if (_isCharSelecShowing)
            {
                if (allPlayers[1].GetButtonUp("Push2") && !_secondPress)
                {
                    otherPlayers.Add(ReInput.players.GetPlayer("Player" + 2));
                    _secondPress = true;
                    for (int i = 0; i < otherPlayers.Count; i++)
                    {
                        if (otherPlayers[i].name == allPlayers[1].name)
                        {
                            secondPlayerIndex = i;
                        }
                    }
                    switch (secondPlayerIndex)
                    {
                    case 1:
                        _secondPlayerIsHere = true;
                        break;

                    case 2:
                        _thirdPlayerIsHere = true;
                        break;

                    case 3:
                        _fourthPlayerIsHere = true;
                        break;
                    }
                }
                if (allPlayers[2].GetButtonUp("Push3") && !_thirdPress)
                {
                    otherPlayers.Add(ReInput.players.GetPlayer("Player" + 3));
                    _thirdPress = true;
                    for (int i = 0; i < otherPlayers.Count; i++)
                    {
                        if (otherPlayers[i].name == allPlayers[2].name)
                        {
                            thirdPlayerIndex = i;
                        }
                    }
                    switch (thirdPlayerIndex)
                    {
                    case 1:
                        _secondPlayerIsHere = true;
                        break;

                    case 2:
                        _thirdPlayerIsHere = true;
                        break;

                    case 3:
                        _fourthPlayerIsHere = true;
                        break;
                    }
                }
                if (allPlayers[3].GetButtonUp("Push4") && !_fourthPress)
                {
                    otherPlayers.Add(ReInput.players.GetPlayer("Player" + 4));
                    _fourthPress = true;
                    for (int i = 0; i < otherPlayers.Count; i++)
                    {
                        if (otherPlayers[i].name == allPlayers[3].name)
                        {
                            fourthPlayerIndex = i;
                        }
                    }
                    switch (fourthPlayerIndex)
                    {
                    case 1:
                        _secondPlayerIsHere = true;
                        break;

                    case 2:
                        _thirdPlayerIsHere = true;
                        break;

                    case 3:
                        _fourthPlayerIsHere = true;
                        break;
                    }
                }

                if (otherPlayers.Count >= 2)
                {
                    if (otherPlayers[1].GetButtonUp("BackMenu" + (otherPlayers[1].name.Substring(otherPlayers[1].name.Length - 1))))
                    {
                        switch (int.Parse(otherPlayers[1].name.Substring(otherPlayers[1].name.Length - 1)))
                        {
                        case 2:
                            _secondPress = false;
                            break;

                        case 3:
                            _thirdPress = false;
                            break;

                        case 4:
                            _fourthPress = false;
                            break;
                        }
                        otherPlayers.Remove(ReInput.players.GetPlayer("Player" + (otherPlayers[1].name.Substring(otherPlayers[1].name.Length - 1))));
                    }


                    if (otherPlayers.Count >= 3)
                    {
                        if (otherPlayers[2].GetButtonUp("BackMenu" + (otherPlayers[2].name.Substring(otherPlayers[2].name.Length - 1))))
                        {
                            switch (int.Parse(otherPlayers[2].name.Substring(otherPlayers[2].name.Length - 1)))
                            {
                            case 2:
                                _secondPress = false;
                                break;

                            case 3:
                                _thirdPress = false;
                                break;

                            case 4:
                                _fourthPress = false;
                                break;
                            }
                            otherPlayers.Remove(ReInput.players.GetPlayer("Player" + (otherPlayers[2].name.Substring(otherPlayers[2].name.Length - 1))));
                            for (int i = 0; i < otherPlayers.Count; i++)
                            {
                                if (otherPlayers[i].name == allPlayers[3].name)
                                {
                                    fourthPlayerIndex = i;
                                }
                                print("remove player " + i + " = " + otherPlayers[i].name);
                            }
                        }
                    }


                    if (otherPlayers.Count >= 4)
                    {
                        if (otherPlayers[3].GetButtonUp("BackMenu" + (otherPlayers[3].name.Substring(otherPlayers[3].name.Length - 1))))
                        {
                            switch (int.Parse(otherPlayers[3].name.Substring(otherPlayers[3].name.Length - 1)))
                            {
                            case 2:
                                _secondPress = false;
                                break;

                            case 3:
                                _thirdPress = false;
                                break;

                            case 4:
                                _fourthPress = false;
                                break;
                            }
                            otherPlayers.Remove(ReInput.players.GetPlayer("Player" + (otherPlayers[3].name.Substring(otherPlayers[3].name.Length - 1))));
                            for (int i = 0; i < otherPlayers.Count; i++)
                            {
                                if (otherPlayers[i].name == allPlayers[3].name)
                                {
                                    fourthPlayerIndex = i;
                                }
                                print("remove player " + i + " = " + otherPlayers[i].name);
                            }
                        }
                    }
                }

                if (otherPlayers.Count >= 1)
                {
                    readyButton[1].sprite = outSprite;
                    OtherJoin[0].SetActive(true);
                    OtherPlayerName[0].SetActive(false);
                    OtherPlayerNumber[0].SetActive(false);
                    OtherPlayerFace[0].SetActive(false);
                    mouvementImageP2[0].gameObject.SetActive(false);
                    mouvementImageP2[1].gameObject.SetActive(false);
                }
                if (otherPlayers.Count >= 2)
                {
                    inputXPlayer2 = -otherPlayers[1].GetAxis("HorizontalJoy2");
                    OtherJoin[0].SetActive(false);
                    OtherPlayerName[0].SetActive(true);
                    OtherPlayerNumber[0].SetActive(true);
                    OtherPlayerFace[0].SetActive(true);
                    mouvementImageP2[0].gameObject.SetActive(true);
                    mouvementImageP2[1].gameObject.SetActive(true);


                    readyButton[2].sprite = outSprite;
                    OtherJoin[1].SetActive(true);
                    OtherPlayerName[1].SetActive(false);
                    OtherPlayerNumber[1].SetActive(false);
                    OtherPlayerFace[1].SetActive(false);
                    mouvementImageP3[0].gameObject.SetActive(false);
                    mouvementImageP3[1].gameObject.SetActive(false);
                    if (otherPlayers.Count >= 3)
                    {
                        //Gère à quel joueur attribué quel action
                        inputXPlayer3 = -otherPlayers[2].GetAxis("HorizontalJoy3");
                        OtherJoin[1].SetActive(false);
                        OtherPlayerName[1].SetActive(true);
                        OtherPlayerNumber[1].SetActive(true);
                        OtherPlayerFace[1].SetActive(true);
                        mouvementImageP3[0].gameObject.SetActive(true);
                        mouvementImageP3[1].gameObject.SetActive(true);


                        readyButton[3].sprite = outSprite;
                        OtherJoin[2].SetActive(true);
                        OtherPlayerName[2].SetActive(false);
                        OtherPlayerNumber[2].SetActive(false);
                        OtherPlayerFace[2].SetActive(false);
                        mouvementImageP4[0].gameObject.SetActive(false);
                        mouvementImageP4[1].gameObject.SetActive(false);

                        if (otherPlayers.Count >= 4)
                        {
                            //Gère à quel joueur attribué quel action
                            inputXPlayer4 = -otherPlayers[3].GetAxis("HorizontalJoy4");
                            OtherJoin[2].SetActive(false);
                            OtherPlayerName[2].SetActive(true);
                            OtherPlayerNumber[2].SetActive(true);
                            OtherPlayerFace[2].SetActive(true);
                            mouvementImageP4[0].gameObject.SetActive(true);
                            mouvementImageP4[1].gameObject.SetActive(true);
                        }
                    }
                }
                else
                {
                    readyButton[2].sprite = outSprite;
                }

                if (inputXPlayer1 > 0.2f)
                {
                    getMenuInfoScript.setPlayerMouvementMode(0, true);
                }
                else if (inputXPlayer1 < -0.2f)
                {
                    getMenuInfoScript.setPlayerMouvementMode(0, false);
                }

                if (inputXPlayer2 > 0.2f)
                {
                    getMenuInfoScript.setPlayerMouvementMode(1, true);
                }
                else if (inputXPlayer2 < -0.2f)
                {
                    getMenuInfoScript.setPlayerMouvementMode(1, false);
                }

                if (inputXPlayer3 > 0.2f)
                {
                    getMenuInfoScript.setPlayerMouvementMode(2, true);
                }
                else if (inputXPlayer3 < -0.2f)
                {
                    getMenuInfoScript.setPlayerMouvementMode(2, false);
                }

                if (inputXPlayer4 > 0.2f)
                {
                    getMenuInfoScript.setPlayerMouvementMode(3, true);
                }
                else if (inputXPlayer4 < -0.2f)
                {
                    getMenuInfoScript.setPlayerMouvementMode(3, false);
                }
            }
            if (_isOnOptions && _player.GetButtonDown("BackMenu"))
            {
                playerEntity.enabled = true;
                optionsPanel.SetActive(false);
                _isOnOptions           = false;
                _hasOptionOrPlayOpened = false;
            }
            if (_isOnOptions && (EventSystem.current.currentSelectedGameObject.tag == "Vibrations"))
            {
                if (-inputXPlayer1 > 0.2f)
                {
                    getMenuInfoScript.SetVibrationsValue(false);
                }
                else if (-inputXPlayer1 < -0.2f)
                {
                    getMenuInfoScript.SetVibrationsValue(true);
                    Vibration(_player, 0, 1.0f, 0.1f);
                }
            }


            #region Check if everyone ready
            if (!_isPOneReady)
            {
                readyButtonConfirm[0].fillAmount = timerPOne;
            }
            if (!_isPTwoReady)
            {
                readyButtonConfirm[1].fillAmount = timerPTwo;
            }
            if (!_isPThreeReady)
            {
                readyButtonConfirm[2].fillAmount = timerPThree;
            }
            if (!_isPFourReady)
            {
                readyButtonConfirm[3].fillAmount = timerPFour;
            }
            #endregion


            #region How to tell if ready
            //if (_isCharSelecShowing && _player.GetButtonDown("BackMenu"))
            //{
            //    selecPanel.SetActive(false);
            //    //ShowPlayerNumberSelection();
            //    _isPOneReady = false;
            //    _isPTwoReady = false;
            //    _isPThreeReady = false;
            //    _isPFourReady = false;
            //    _isCharSelecShowing = false;

            //}
            //quand les joueurs garde le bouton a appuyé, le timer augmente et, passé un certain temps, le joueur est considérer comme prêt
            //dès que tous les joueurs sont prêts, le jeu se lance
            if (_isCharSelecShowing && _player.GetButton("Push1"))
            {
                timerPOne += Time.deltaTime;
            }
            else if (_isCharSelecShowing && _player.GetButtonUp("Push1"))
            {
                timerPOne = 0;
            }
            if (timerPOne >= 1)
            {
                _isPOneReady = true;
            }
            if (_isPOneReady)
            {
                readyButton[0].sprite = readySprite;
            }
            else
            {
                readyButton[0].sprite = originalSprite;
            }

            if (otherPlayers.Count >= 2)
            {
                if (_isCharSelecShowing && otherPlayers[1].GetButton("Push" + (otherPlayers[1].name.Substring(otherPlayers[1].name.Length - 1))))
                {
                    timerPTwo += Time.deltaTime;
                }
                else if (_isCharSelecShowing && otherPlayers[1].GetButtonUp("Push" + (otherPlayers[1].name.Substring(otherPlayers[1].name.Length - 1))))
                {
                    timerPTwo = 0;
                }
                if (timerPTwo >= 1)
                {
                    _isPTwoReady = true;
                }
                if (_isPTwoReady)
                {
                    readyButton[1].sprite = readySprite;
                }
                else
                {
                    readyButton[1].sprite = originalSprite;
                }
            }


            if (otherPlayers.Count > 2)
            {
                if (_isCharSelecShowing && otherPlayers[2].GetButton("Push" + (otherPlayers[2].name.Substring(otherPlayers[2].name.Length - 1))))
                {
                    timerPThree += Time.deltaTime;
                }
                else if (_isCharSelecShowing && otherPlayers[2].GetButtonUp("Push" + (otherPlayers[2].name.Substring(otherPlayers[2].name.Length - 1))))
                {
                    timerPThree = 0;
                }
                if (timerPThree >= 1)
                {
                    _isPThreeReady = true;
                }
                if (_isPThreeReady)
                {
                    readyButton[2].sprite = readySprite;
                }
                else
                {
                    readyButton[2].sprite = originalSprite;
                }
            }


            if (otherPlayers.Count > 3)
            {
                if (_isCharSelecShowing && otherPlayers[3].GetButton("Push" + (otherPlayers[3].name.Substring(otherPlayers[3].name.Length - 1))))
                {
                    timerPFour += Time.deltaTime;
                }
                else if (_isCharSelecShowing && otherPlayers[3].GetButtonUp("Push" + (otherPlayers[3].name.Substring(otherPlayers[3].name.Length - 1))))
                {
                    timerPFour = 0;
                }
                if (timerPFour >= 1)
                {
                    _isPFourReady = true;
                }
                if (_isPFourReady)
                {
                    readyButton[3].sprite = readySprite;
                }
                else
                {
                    readyButton[3].sprite = originalSprite;
                }
            }


            #endregion

            #region Start game when all ready
            if (otherPlayers.Count == 2)
            {
                if (_isPOneReady && _isPTwoReady)
                {
                    getMenuInfoScript.GetPlayerNumbers(otherPlayers.Count);
                    StartGame();
                }
            }
            else if (otherPlayers.Count == 3)
            {
                if (_isPOneReady && _isPTwoReady && _isPThreeReady)
                {
                    getMenuInfoScript.GetPlayerNumbers(otherPlayers.Count);
                    StartGame();
                }
            }
            else
            {
                if (_isPOneReady && _isPTwoReady && _isPThreeReady && _isPFourReady)
                {
                    getMenuInfoScript.GetPlayerNumbers(otherPlayers.Count);
                    StartGame();
                }
            }
            #endregion
        }
    }
Beispiel #3
0
    private void Update()
    {
        float velX = Mathf.Abs(_myRb.velocity.x);
        float velY = Mathf.Abs(_myRb.velocity.y);

        velX = Mathf.Clamp(velX, 0, 3);
        velY = Mathf.Clamp(velY, 0, 3);

        if (velY >= 1 && velX >= 1)
        {
            squash = ((velY + velX) / speedSquashMultiplier);
        }
        else
        {
            squash = 0.0001f;
        }

        playerSprite.transform.localScale = new Vector3((squash / -2) + originalScale, squash + originalScale, playerSprite.transform.localScale.z);


        if (playerScaleHitWall)
        {
            squashWall = ((velX + velY) / scaleMultiplier);

            timerScale += Time.deltaTime;
            float lerpScaleRatio = timerScale / timerScaleMax;
            playerSprite.transform.localScale = Vector3.Lerp(new Vector3(originalScale, originalScale, originalScale), new Vector3(squashWall + originalScale, (squashWall / -2) + originalScale, playerSprite.transform.localScale.z), lerpScaleRatio);
            if (lerpScaleRatio >= 1)
            {
                timerRescale += Time.deltaTime;
                float lerpRescaleRatio = timerRescale / timerRescaleMax;
                playerSprite.transform.localScale = Vector3.Lerp(playerSprite.transform.localScale, new Vector3(originalScale, originalScale, originalScale), lerpRescaleRatio);
                if (lerpRescaleRatio >= 1)
                {
                    timerScale         = 0;
                    timerRescale       = 0;
                    playerScaleHitWall = false;
                }
            }
        }


        //si les onomatopées sont activés, lance le timer de désactivation
        if (onomatopéesSprite.enabled)
        {
            onomatopéeTimer += Time.deltaTime;
            if (onomatopéeTimer >= onomatopéeTimerMax)
            {
                onomatopéeTimer = 0;
                _animator.SetBool("isHit", false);
                _animator.SetBool("isHitting", false);
                _playerScoreImage.sprite = _playerScoreImageSprites[2];

                onomatopéesSprite.enabled = false;
            }
        }

        //si la jauge d'ulti est inférieure à 1/3 du max, ne fait pas apparaitre les FXs
        if (_ultiCurrentCharge < ultiChargeMax * 0.33f)
        {
            UltiFxStates[0].SetActive(false);
            UltiFxStates[1].SetActive(false);
            UltiFxStates[2].SetActive(false);
        }

        //permet de changer la position du sprite qui apparait quand on touche le mur et de lui lancer son timer de désactivation
        if (wallSpriteTransform.gameObject.activeSelf)
        {
            wallSpriteTransform.position      = wallSpritePosition;
            wallSpriteTransform.localPosition = new Vector3(wallSpriteTransform.localPosition.x, wallSpriteTransform.localPosition.y, 8);
            wallHitSpriteTimer += Time.deltaTime;
            if (wallHitSpriteTimer >= wallHitSpriteTimerMax)
            {
                wallHitSpriteTimer = 0;
                wallSpriteTransform.gameObject.SetActive(false);
            }
        }

        //si on a utilisé l'ulti, reset la jauge.
        if (_ultiCurrentCharge == ultiChargeMax && !_isUltiPossible)
        {
            _ultiCurrentCharge = 0;
        }

        //active et désactive le son de charge.
        if (_playerInput == INPUTSTATE.GivingInput && _mustPlayCastSound)
        {
            if (_newSoundManagerScript != null)
            {
                _newSoundManagerScript.PlayCharge(int.Parse(gameObject.tag.Substring(gameObject.tag.Length - 1)) - 1);
            }
            _mustPlayCastSound = false;
        }
        else if (_playerInput == INPUTSTATE.None)
        {
            if (_newSoundManagerScript != null)
            {
                _newSoundManagerScript.StopCharge(int.Parse(gameObject.tag.Substring(gameObject.tag.Length - 1)) - 1);
            }
            _mustPlayCastSound = true;
        }

        //active les différents stades de vibrations

        if (_menuInformationScript == null || _menuInformationScript.GetVibrationsValue())
        {
            if (powerJauge.fillAmount > vibrationTreshold)
            {
                if (gameObject.tag == "Player1")
                {
                    _playerManagerScript.Vibration(_playerManagerScript.player[0], 0, 1.0f, vibrationTreshold * 0.5f);
                }
                else if (gameObject.tag == "Player2")
                {
                    _playerManagerScript.Vibration(_playerManagerScript.player[1], 0, 1.0f, vibrationTreshold * 0.5f);
                }
                if (gameObject.tag == "Player3")
                {
                    _playerManagerScript.Vibration(_playerManagerScript.player[2], 0, 1.0f, vibrationTreshold * 0.5f);
                }
                else if (gameObject.tag == "Player4")
                {
                    _playerManagerScript.Vibration(_playerManagerScript.player[3], 0, 1.0f, vibrationTreshold * 0.5f);
                }
                vibrationTreshold += 0.2f;
            }
            else if (powerJauge.fillAmount == vibrationTreshold)
            {
                if (gameObject.tag == "Player1")
                {
                    _playerManagerScript.Vibration(_playerManagerScript.player[0], 0, 1.0f, tooMuchPowerTimerMax);
                }
                else if (gameObject.tag == "Player2")
                {
                    _playerManagerScript.Vibration(_playerManagerScript.player[1], 0, 1.0f, tooMuchPowerTimerMax);
                }
                if (gameObject.tag == "Player3")
                {
                    _playerManagerScript.Vibration(_playerManagerScript.player[2], 0, 1.0f, tooMuchPowerTimerMax);
                }
                else if (gameObject.tag == "Player4")
                {
                    _playerManagerScript.Vibration(_playerManagerScript.player[3], 0, 1.0f, tooMuchPowerTimerMax);
                }
            }
        }
    }
Beispiel #4
0
    // Update is called once per frame
    void Update()
    {
        //active l'animation et lui donne la bonne position
        if (hasPositionBeenTaken)
        {
            Vector3 dirFromAtoB = (Vector3.zero - transform.GetChild(0).transform.position).normalized;
            float   dotProd     = Vector3.Dot(dirFromAtoB, transform.GetChild(0).transform.forward);
            playerOutAnim.transform.eulerAngles = new Vector3(0, 0, transform.eulerAngles.z + 180);

            //si le sprite du joueur regarde vers l'arène
            if (dotProd > 0)
            {
                playerOutAnim.transform.eulerAngles = new Vector3(0, 0, transform.eulerAngles.z);
            }


            playerOutAnim.transform.position = new Vector3(playerOutPosition.x, playerOutPosition.y, transform.position.z);
            // transform.GetChild(0).transform.LookAt(new Vector3(0, 0, 0));
            playerOutAnim.SetActive(true);
            if (!_hasSoundPlayed)
            {
                _newSoundManagerScript.PlaySound("Elimination");
                _newSoundManagerScript.PlaySound("Crowd");
                _hasSoundPlayed = true;
            }
            if (_scoreManagerScript.GetHasGameEnded())
            {
                _scoreManagerScript.RestartMenu();
            }
        }

        //permet de reset les valeurs quand l'animation est finie
        //if(_hasAnimationEnded)
        if (playerOutAnim.GetComponent <ParticleSystem>().isStopped&& _hasSoundPlayed)
        {
            hasPositionBeenTaken             = false;
            playerOutAnim.transform.position = Vector3.zero;
            playerOutAnim.SetActive(false);
            GetComponent <Rigidbody2D>().velocity = Vector2.zero;
            _hasAnimationEnded = false;
            _hasSoundPlayed    = false;
        }

        if (_isCrackActive)
        {
            if (!_hasCrackPositionBeenGiven)
            {
                _ultiCrack.transform.position = new Vector3(transform.position.x, transform.position.y, -1.9f);
                _hasCrackPositionBeenGiven    = true;
                _ultiCrack.SetActive(true);
            }
            ultiCrackTimer += Time.deltaTime;
            float ratio = ultiCrackTimer / ultiCrackTimerMax;

            _ultiCrack.GetComponent <SpriteRenderer>().color = Color.Lerp(_crackStartingColor, new Color(255, 255, 255, 0), ratio);
            if (ratio >= 1)
            {
                ultiCrackTimer = 0;
                _ultiCrack.GetComponent <SpriteRenderer>().color = _crackStartingColor;
                _hasCrackPositionBeenGiven = false;
                _ultiCrack.SetActive(false);
                _isCrackActive = false;
            }
        }

        //active la shockwave pendant un certain temps
        if (isShockWaveButtonPressed && _playerEntityScript.GetUltiBool() && !_shockWaveHitScript.GetHaveIBeenHit())
        {
            if (!_hasPlayedSound)
            {
                _newSoundManagerScript.PlaySound("Ulti");
                _hasPlayedSound = true;
            }
            shockWaveDuration -= Time.deltaTime;
            _playerEntityScript.resetUltiCurrentCharge();
            if (_menuInformationScript == null || _menuInformationScript.GetVibrationsValue())
            {
                if (shockWaveDuration > 0)
                {
                    if (gameObject.tag == "Player1")
                    {
                        _playerManagerScript.Vibration(_playerManagerScript.player[0], 0, 1.0f, shockWaveDurationMax);
                    }
                    else if (gameObject.tag == "Player2")
                    {
                        _playerManagerScript.Vibration(_playerManagerScript.player[1], 0, 1.0f, shockWaveDurationMax);
                    }
                    else if (gameObject.tag == "Player3")
                    {
                        _playerManagerScript.Vibration(_playerManagerScript.player[2], 0, 1.0f, shockWaveDurationMax);
                    }
                    else if (gameObject.tag == "Player4")
                    {
                        _playerManagerScript.Vibration(_playerManagerScript.player[3], 0, 1.0f, shockWaveDurationMax);
                    }
                }
            }

            shockWaveSprite.SetActive(true);
            _isCrackActive = true;
            //set un cercle qui check les colliders dedans, si il y a un joueur, il le rajoute dans un tableau et permet d'accéder à l'objet qui contient le collider
            Collider2D[] enemiesCollider = Physics2D.OverlapCircleAll(shockWavePosition.position, shockWaveRadius, EnemyMask);
            if (enemiesCollider.Length > 0)
            {
                // pour chaque élément dans le tableau, lui ajoute un addforce pour la shockwave et un compteur de dommages pour les murs
                for (int i = 0; i < enemiesCollider.Length; i++)
                {
                    Vector3 moveDirection = enemiesCollider[i].transform.position - this.transform.position;

                    enemiesCollider[i].GetComponent <ShockwaveHit>().SetHaveIBeenHitTrue();

                    enemiesCollider[i].GetComponent <Rigidbody2D>().velocity = moveDirection.normalized * Time.deltaTime * pushbackIntensity;
                    Debug.Log("Hit");
                }
            }
            else
            {
                //si rien n'est check
                Debug.Log("Not hit");
            }
            //lorsque la durée de la shockwave est finie, reset les varibles utilisées
            if (shockWaveDuration <= 0)
            {
                shockWaveDuration = shockWaveDurationMax;
                _playerEntityScript.SetUltiBoolFalse();
                shockWaveSprite.SetActive(false);
                isShockWaveButtonPressed = false;
            }
        }
    }