コード例 #1
0
    private void OnTriggerStay(Collider other)
    {
        if (Input.GetButtonDown("Mine") && lastPosition == transform.position)
        {
            if (other.tag == "Coal")
            {
                playerAnimator.SetTrigger("IsMining");
                particles.Play();
                _piocheAudioController.PlayOne();

                if (other.gameObject.GetComponent <CoalBlock>().GetBlocLife() > 0)
                {
                    GazLevel gazLevel = GetCurrentGazLevel();
                    gazLevel.IncreaseGazLevel();
                    if (gazLevel.GazRate > 100)
                    {
                        Debug.Log("Boum !");

                        Boum();
                    }

                    other.gameObject.GetComponent <CoalBlock>().MineBlock();
                }
            }
            else
            {
                Debug.Log("not coal : " + Hit.point);
            }
        }
    }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        if (!boum)
        {
            lastPosition = transform.position;
            //particles.Stop();
            //gameObject.transform.position += new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
            //gameObject.transform.Translate(new Vector3(0.5f * Input.GetAxis("Horizontal"), 0, 0.5f * Input.GetAxis("Vertical")));
            Vector3 move = new Vector3(CoeffHorX * Input.GetAxis("Horizontal") + CoeffVerX * Input.GetAxis("Vertical"), 0, CoeffHorZ * Input.GetAxis("Horizontal") + CoeffVerZ * Input.GetAxis("Vertical"));

            _controller.Move(move * Time.deltaTime * Speed);

            if (Input.GetAxis("Horizontal") + Input.GetAxis("Vertical") > 0)
            {
                minerSprite.flipX = false;
            }
            else if (Input.GetAxis("Horizontal") + Input.GetAxis("Vertical") < 0)
            {
                minerSprite.flipX = true;
            }

            /* ce sera pour orienter le personnage.*/
            if (move != Vector3.zero)
            {
                transform.forward = move;
            }

            _velocity.y += Gravity * Time.deltaTime;
            _controller.Move(_velocity * Time.deltaTime);

            if (_controller.isGrounded && _velocity.y < 0)
            {
                _velocity.y = 0f;
            }

            if (/*move == Vector3.zero*/ transform.position == lastPosition)
            {
                playerAnimator.SetBool("IsRunning", false);

                if (oxygenChange)
                {
                    oxygenBar -= oxygenLoss * Time.deltaTime;
                    if (oxygenBar <= 0)
                    {
                        Debug.Log("C'est perdu");
                        SceneManager.LoadScene("GameOverScene");
                    }
                }
            }
            else
            {
                _footStepAudioController.PlayOne();
                playerAnimator.SetBool("IsRunning", true);
                if (oxygenChange)
                {
                    oxygenBar += oxygenGain * Time.deltaTime;
                    if (oxygenBar >= oxygenBarMax)
                    {
                        oxygenBar = oxygenBarMax;
                    }
                }
            }

            if (oxygenBar <= 30)
            {
                _voiceAudioController.PlayOne();
            }

            /* ce sera pour orienter le personnage.*/
            if (move != Vector3.zero)
            {
                transform.forward = move;
            }

            _velocity.y += Gravity * Time.deltaTime;
            _controller.Move(_velocity * Time.deltaTime);

            GazLevel gazLevel = GetCurrentGazLevel();

            playerLight.intensity = (oxygenBar / 100) * 2;


            if (spriteLooker != null)
            {
                spriteLooker.LookCamera();
            }

            if (gazLevel)
            {
                if (gazLevel.GazRate > 100)
                {
                    Debug.Log("Boum !");
                    Boum();
                }

                if (gazLevel.GazRate >= 80)
                {
                    _piouAudioController.PlayHighPanicked();
                    playerAnimator.SetBool("Level2", true);
                    /*Debug.Log("gaz TRUE");*/
                }
                else if (gazLevel.GazRate >= 60)
                {
                    _piouAudioController.PlayLowPanicked();
                    playerAnimator.SetBool("Level2", true);
                    /*Debug.Log("gaz TRUE");*/
                }
                else if (gazLevel.GazRate >= 40)
                {
                    playerAnimator.SetBool("Level2", false);
                    _piouAudioController.Panick();
                    //Debug.Log("gaz FALSE");
                }
                else
                {
                    playerAnimator.SetBool("Level2", false);
                    _piouAudioController.NoPanick();
                    //Debug.Log("gaz FALSE");
                }

                Debug.Log("GAZ LEVEL : " + gazLevel.GazRate);
            }
        }
    }