コード例 #1
0
        private void SetupArmor()
        {
            Weapon = new ArmorState();

            foreach (Items.Armor.ArmorSlot armorType in Items.Armor.ArmorSlotEnum)
            {
                Armor.Add(armorType, new ArmorState());
            }
        }
コード例 #2
0
    // Update is called once per frame

    void Update()
    {
        //dash
        if ((playerDevice.GetControl(InputControlType.LeftTrigger).IsPressed) && (playerDevice.GetControl(InputControlType.LeftBumper).WasReleased) && (spawnShield == false))
        {
            Debug.Log("dash");
            dashState = DashState.DASH_BEGIN;
            Dash();
        }



        if (playerDevice == null)
        {
            return;
        }

        if (playerDevice.GetControl(InputControlType.Action1).IsPressed)
        {
            Debug.Log("Coucou j'appuie sur X");
        }

        Debug.Log(playerIndex);
        //if(playerIndex == 1)

        animator.SetFloat("velocity", Mathf.Abs(rigidBody2D.velocity.x));
        //mouvement gauche droite

        float horizontalInput = playerDevice.LeftStickX;
        float verticalInput   = playerDevice.LeftStickY;

        shieldOn = false;
        if (canMove == true)
        {
            Vector2 velocity = new Vector2(horizontalInput * playerVelocity, rigidBody2D.velocity.y);
            rigidBody2D.velocity = velocity;
            //inversion du sprite du personnage
            Vector3 scale = transform.localScale;
            if (rigidBody2D.velocity.x > 0)
            {
                scale.x = Mathf.Abs(scale.x);
            }
            else if (rigidBody2D.velocity.x < 0)
            {
                scale.x = -Mathf.Abs(scale.x);
            }
            transform.localScale = scale;
        }
        else
        {
            //inversion du sprite du personnage
            Vector3 scale = transform.localScale;
            if (horizontalInput > 0)
            {
                scale.x = Mathf.Abs(scale.x);
            }
            else if (horizontalInput < 0)
            {
                scale.x = -Mathf.Abs(scale.x);
            }
            transform.localScale = scale;
        }
        //saut
        bool canJump = Physics2D.OverlapCircle(jumpPosition.position, raycastRadius, mask);

        if (canJump && (playerDevice.GetControl(InputControlType.Action1).IsPressed)) //si appuye sur boutton saut
        {
            rigidBody2D.AddForce(new Vector2(0, jumpForce), ForceMode2D.Impulse);     //donne une impulsion verticale
        }
        //bouclier
        //a mettre dans le code du joueur
        if ((playerDevice.GetControl(InputControlType.RightBumper).IsPressed) && (spawnShield != true))
        {
            shieldThrow = true;
            if (transform.localScale.x > 0)
            {
                GameObject monObject = Instantiate(shieldPrefab, new Vector3(transform.position.x + 5, transform.position.y, -2), Quaternion.identity);
                monObject.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 90));
                monObject.GetComponent <Rigidbody2D>().velocity          = new Vector2(shieldVelocity, verticalInput) * shieldVelocity;
                monObject.GetComponent <shieldMovement>().shieldPlayerId = playerIndex;
            }
            if (transform.localScale.x < 0)
            {
                GameObject monObject = Instantiate(shieldPrefab, new Vector3(transform.position.x - 5, transform.position.y, -2), Quaternion.identity);
                monObject.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 90));
                monObject.GetComponent <Rigidbody2D>().velocity          = new Vector2(-shieldVelocity, verticalInput) * shieldVelocity;
                monObject.GetComponent <shieldMovement>().shieldPlayerId = playerIndex;
            }
            spawnShield = true;
        }
        //levée de bouclier
        if (dashState == DashState.NOT_DASH)
        {
            if ((playerDevice.GetControl(InputControlType.LeftBumper).IsPressed) && (spawnShield == false))
            {
                rigidBody2D.constraints = RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezeRotation;

                animator.SetBool("ShieldFlanc", true);
                armorState = ArmorState.SHIELD_UP;
                canMove    = false;
                Debug.Log("boucliers");
                //playerShield.SetActive(true);
                shieldOn = true;
                colliderShieldFlanc.enabled = true;
                colliderShieldTop.enabled   = false;
                colliderShieldDown.enabled  = false;
                if (playerDevice.LeftStickY > 0.2f)
                {
                    Debug.Log("prout");
                    colliderShieldTop.enabled   = true;
                    colliderShieldDown.enabled  = false;
                    colliderShieldFlanc.enabled = false;
                    //playerShield.SetActive(false);
                    shieldDown = false;
                    shieldUP   = true;
                }
                else if (playerDevice.LeftStickY < -0.2f)
                {
                    //playerShield.SetActive(false);
                    colliderShieldDown.enabled  = true;
                    colliderShieldTop.enabled   = false;
                    colliderShieldFlanc.enabled = false;
                    shieldDown = true;
                    shieldUP   = false;
                }
                else
                {
                    colliderShieldTop.enabled   = false;
                    colliderShieldDown.enabled  = false;
                    colliderShieldFlanc.enabled = true;
                    shieldDown = false;
                    shieldUP   = false;
                    //playerShield.SetActive(false);
                }
            }
            else
            {
                rigidBody2D.constraints     = RigidbodyConstraints2D.FreezeRotation;
                colliderShieldTop.enabled   = false;
                colliderShieldDown.enabled  = false;
                colliderShieldFlanc.enabled = false;
                animator.SetBool("ShieldFlanc", false);
                armorState = ArmorState.SHIELD_LESS;
                canMove    = true;
                //playerShield.SetActive(false);
                shieldOn   = false;
                shieldDown = false;
                shieldUP   = false;
            }
        }
        animator.SetBool("shieldDown", shieldDown);
        animator.SetBool("shieldUP", shieldUP);
        animator.SetBool("shieldThrow", shieldThrow);
    }