Пример #1
0
        // Update is called once per frame
        void Update()
        {
            Vector2 vitesse = Vector2.zero;

            if (Input.GetKey(KeyCode.UpArrow) && controls == PlayerControls.ArrowAnd0 ||
                Input.GetKey(KeyCode.Z) && controls == PlayerControls.ZQSDF)
            {
                vitesse += Vector2.up;
                Instantiate(dust.gameObject, body.position, Quaternion.identity);
            }

            if (Input.GetKey(KeyCode.DownArrow) && controls == PlayerControls.ArrowAnd0 ||
                Input.GetKey(KeyCode.S) && controls == PlayerControls.ZQSDF)
            {
                vitesse += Vector2.down;
                Instantiate(dust.gameObject, body.position, Quaternion.identity);
            }

            if (Input.GetKey(KeyCode.LeftArrow) && controls == PlayerControls.ArrowAnd0 ||
                Input.GetKey(KeyCode.Q) && controls == PlayerControls.ZQSDF)
            {
                vitesse += Vector2.left;
                spriteRenderer.flipX = true;
                Instantiate(dust.gameObject, body.position, Quaternion.identity);
            }

            if (Input.GetKey(KeyCode.RightArrow) && controls == PlayerControls.ArrowAnd0 ||
                Input.GetKey(KeyCode.D) && controls == PlayerControls.ZQSDF)
            {
                vitesse += Vector2.right;
                spriteRenderer.flipX = false;
                Instantiate(dust.gameObject, body.position, Quaternion.identity);
            }

            if ((Input.GetKeyDown(KeyCode.Keypad0) && controls == PlayerControls.ArrowAnd0 ||
                 Input.GetKeyDown(KeyCode.F) && controls == PlayerControls.ZQSDF) && rollCooldown <= 0)
            {
                animator.Play(Anims.Roll);
                rollCooldown = rollCooldownDuration;
            }

            if (animator.CurrentAnimation.name != Anims.Roll || animator.LoopCount >= 1)
            {
                if (vitesse.magnitude > 0)
                {
                    animator.Play(Anims.Run);
                }
                else
                {
                    animator.Play(Anims.Iddle);
                }
            }

            body.velocity = vitesse.normalized * speed;

            rollCooldown -= Time.deltaTime;
        }
Пример #2
0
        // Update is called once per frame
        void Update()
        {
            Vector2 vitesse = Vector2.zero;

            if (Input.GetKey(KeyCode.UpArrow) && controls == PlayerControls.ArrowAnd0 ||
                Input.GetKey(KeyCode.Z) && controls == PlayerControls.ZQSDF)
            {
                vitesse += Vector2.up;
            }

            if (Input.GetKey(KeyCode.DownArrow) && controls == PlayerControls.ArrowAnd0 ||
                Input.GetKey(KeyCode.S) && controls == PlayerControls.ZQSDF)
            {
                vitesse += Vector2.down;
            }

            if (Input.GetKey(KeyCode.LeftArrow) && controls == PlayerControls.ArrowAnd0 ||
                Input.GetKey(KeyCode.Q) && controls == PlayerControls.ZQSDF)
            {
                vitesse += Vector2.left;
                spriteRenderer.flipX = true;
            }

            if (Input.GetKey(KeyCode.RightArrow) && controls == PlayerControls.ArrowAnd0 ||
                Input.GetKey(KeyCode.D) && controls == PlayerControls.ZQSDF)
            {
                vitesse += Vector2.right;
                spriteRenderer.flipX = false;
            }

            if ((Input.GetKeyDown(KeyCode.Keypad1) && controls == PlayerControls.ArrowAnd0 ||
                 Input.GetKey(KeyCode.F) && controls == PlayerControls.ZQSDF) && rollCooldown <= 0)
            {
                animator.Play(Anims.Roll);
                rollCooldown = rollCooldownDuration;
            }

            if (animator.CurrentAnimation.name != Anims.Roll || animator.LoopCount >= 1)
            {
                var dirtFx = DirtFX.emission;
                if (vitesse.magnitude > 0)
                {
                    animator.Play(Anims.Run);
                    dirtFx.enabled = true;
                }
                else
                {
                    animator.Play(Anims.Iddle);
                    dirtFx.enabled = false;
                }
            }

            rollCooldown -= Time.deltaTime;
            body.velocity = vitesse.normalized * speed;
        }