コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        if (useBaseControl)
        {
            if (isTalk == false)
            {
                if (Cc.isGrounded)
                {
                    moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
                    //CameraMoveCustom = new Vector3()
                    moveDirection  = Camera.main.transform.TransformDirection(moveDirection);   //doit ignorer le Y de la cam sinon fait des bond en arriere
                    moveDirection *= speed;

                    if (Input.GetButtonDown("Jump"))
                    {
                        moveDirection.y = jumpSpeed;
                    }
                    else
                    {
                        moveDirection.y = 0.0f;
                    }
                }


                moveDirection.y -= gravity * Time.deltaTime;

                Cc.Move(moveDirection * Time.deltaTime);



                //rotation du perso
                Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0.0f, Input.GetAxis("Vertical"));
                movement   = Camera.main.transform.TransformDirection(movement);
                movement.y = 0f;

                model.transform.rotation = Quaternion.LookRotation(movement);
                model.transform.rotation = Quaternion.Slerp(model.transform.rotation, Quaternion.LookRotation(movement), 0.15f);



                if (Input.GetKey(runKey)) //course
                {                         /*
                                           *     speed = runSpeed;
                                           * anim.SetBool("isRunning", false);
                                           * anim.SetBool("isWalking", true);
                                           */
                }
                else
                {
                    speed = defaultSpeed;
                    //anim.SetBool("isRunning", true);
                    anim.SetBool("isWalking", false);
                }



                if (Input.GetKey(rightWalk) || Input.GetKey(leftWalk) || Input.GetKey(backWalk) || Input.GetKey(frontWalk))
                {
                    if (Time.time > nextActionTime)
                    {
                        nextActionTime += period;
                        //Instantiate(particulePas, pasPivot.transform.position, pasPivot.transform.rotation);

                        particulePas.GetComponent <ParticleSystem>().Play();

                        audioS.clip = walkSFX[Random.Range(0, walkSFX.Length)];
                        audioS.Play();
                    }


                    qTo = model.transform.rotation;
                    anim.SetBool("isRunning", true);
                }
                else
                {
                    model.transform.rotation = qTo;
                    anim.SetBool("isRunning", false);
                }


                look.stop = false;
                maskBody  = false;
            }
            else
            {
                look.stop = true;
                anim.SetBool("isRunning", false);
                anim.SetBool("isWalking", false);

                model.transform.rotation = new Quaternion(0, 0, 0, 0);
            }


            if (maskBody)
            {
                model.SetActive(false);
            }
            else
            {
                model.SetActive(true);
            }
        }

        if (item != null && item.isPick)//place l item ds la main
        {
            item.transform.position = itemHand.position;
            item.transform.rotation = itemHand.rotation;

            if (item.itemType == itemPick.type.graineGland && GameManager.s_Singleton.progression == 2 && GameManager.s_Singleton.queteSanglier == false)
            {
                ui.sanglierTextSpawn();
            }
            else if (item.itemType == itemPick.type.baton && GameManager.s_Singleton.progression == 2 && GameManager.s_Singleton.queteSanglier == false)
            {
                ui.sanglierTextSpawnFaux();
            }
            else if (item.itemType != itemPick.type.graineGland && item.itemType != itemPick.type.baton && GameManager.s_Singleton.progression == 2 && GameManager.s_Singleton.queteSanglier == false)
            {
                ui.sanglierTextSpawnFauxFleur();
            }
            else if (GameManager.s_Singleton.progression == 2 && GameManager.s_Singleton.queteSanglier == true)
            {
                ui.sanglierTextSpawnAccompli();
            }


            if (item.itemType == itemPick.type.HelleboreOrient && GameManager.s_Singleton.progression == 6 && GameManager.s_Singleton.queteChien == false)
            {
                ui.chienChatTextSpawn();
            }
            else if (item.itemType != itemPick.type.HelleboreOrient && GameManager.s_Singleton.progression == 6 && GameManager.s_Singleton.queteChien == false)
            {
                ui.chienChatTextSpawnFaux();
            }
            else if (GameManager.s_Singleton.progression == 6 && GameManager.s_Singleton.queteChien == true)
            {
                ui.chienChatTextSpawnAccompli();
            }
        }

        //interaction

        if (Input.GetKeyDown(interactionKey) && item != null && type == PlayerMovement.interactionType.item)
        {
            item.isPick = true;

            audioS.clip  = ramassageItemSound;
            audioS.pitch = Random.Range(1, 1.4f);
            audioS.Play();

            GameManager.s_Singleton.SauvegadeJeu();

            StartCoroutine(CollectItem());
        }
        if (Input.GetKeyDown(interactionKey) && potActuel != null && type == PlayerMovement.interactionType.pot)
        {
            audioS.clip  = ramassageItemSound;
            audioS.pitch = Random.Range(1, 1.4f);
            audioS.Play();

            GameManager.s_Singleton.SauvegadeJeu();

            if (potActuel.full == false)
            {
                potActuel.PlaceFlower();
            }
        }

        if (Input.GetKeyDown(interactionKey) && bancActuel != null && bancActuel.isBanc == false && type == PlayerMovement.interactionType.banc)
        {
            bancActuel.EnterBanc();
        }

        if (Input.GetKeyDown(interactionKey) && dialogueActuel != null && managerDialogue.dialogueActive == false && type == PlayerMovement.interactionType.dialogue)
        {
            //Debug.Log(other);
            dialogueActuel.EventDialogue();
        }

        if (Input.GetKeyDown(interactionKey) && panneau != null && type == PlayerMovement.interactionType.panneau)
        {
            GameManager.s_Singleton.SauvegadeJeu();

            panneau.UpgradeMap();
        }
    }