- Home /
 
               Question by 
               SweetPotatoes · May 04, 2015 at 05:13 AM · 
                c#scripting problemcontrollerlimitgamepad  
              
 
              Limit number of face buttons being simultaneously held.
Hi everyone,
I'm making a game were the play has to move their character by holding down the face buttons and dragging their limbs similar to Mount Your Friends). Though I'm now stuck and have been trying to figure out a way to limit the number of face buttons that can be used simultaneously down to two.
If anyone could help me out on this matter, I would be very grateful. I've cut out a bit of code from the beginning of the FixedUpdate() just to make it shorter to read.
Cheers
 using UnityEngine;
 using System.Collections.Generic;
 using XInputDotNetPure;
 
 public class GamePadSetupP1 : MonoBehaviour {
     
     private bool playerIndexSet = false;
     private int player1 = 1;
     private GamePadState padState;
     private GamePadState prevPadState;
 
     public PlayerIndex playerIndex;
 
     public GameObject leftFoot;
     public GameObject rightFoot;
     public GameObject leftArm;
     public GameObject rightArm;
 
     private aButtonGpadP1 inputA;
     private bButtonGpadP1 inputB;
     private yButtonGpadP1 inputY;
     private xButtonGpadP1 inputX;
 
     public void Start()
     {
         inputA = rightFoot.GetComponent<aButtonGpadP1>();
         inputB = leftFoot.GetComponent<bButtonGpadP1>();
         inputY = leftArm.GetComponent<yButtonGpadP1>();
         inputX = rightArm.GetComponent<xButtonGpadP1>();
     }
 
     public void FixedUpdate()
     {
         if (padState.Buttons.A == ButtonState.Pressed) //When A is held down the players right leg can be moved.
         {
             inputA.InputA();
             Debug.Log("Player 1 Pressed Input A");
         }
         
         if (padState.Buttons.B == ButtonState.Pressed) //When B is held down the players left leg can be moved.
         {
             inputB.InputB();
             Debug.Log("Player 1 Pressed Input B");
         }
         
         if (padState.Buttons.Y == ButtonState.Pressed) //When Y is held down the players left arm can be moved.
         {
             inputY.InputY();
             Debug.Log("Player 1 Pressed Input Y");
         }
         
         if (padState.Buttons.X == ButtonState.Pressed) //When X is held down the players right arm can be moved.
         {
             inputX.InputX();
             Debug.Log("Player 1 Pressed Input X");
         }
     }
 }
               Comment
              
 
               
               
               Best Answer 
               Wiki 
              
 
              Answer by yashpal · May 04, 2015 at 05:27 AM
hello @SweetPotatoes ,
it is really simple
  public void FixedUpdate()
  {
      int countPressedButton =  0; 
      if (padState.Buttons.A == ButtonState.Pressed) //When A is held down the players right leg can be moved.
      {
          inputA.InputA();
          Debug.Log("Player 1 Pressed Input A");
          countPressedButton  ++;
      }
      
      if (padState.Buttons.B == ButtonState.Pressed) //When B is held down the players left leg can be moved.
      {
          inputB.InputB();
          Debug.Log("Player 1 Pressed Input B");
          countPressedButton ++;
      }
      
      if ( (countPressedButton <2) && ( padState.Buttons.Y == ButtonState.Pressed)) //When Y is held down the players left arm can be moved.
      {
          inputY.InputY();
          Debug.Log("Player 1 Pressed Input Y");
          countPressedButton ++;
      }
      
      if ( (countPressedButton <2) && ( padState.Buttons.X == ButtonState.Pressed ) ) //When X is held down the players right arm can be moved.
      {
          inputX.InputX();
          Debug.Log("Player 1 Pressed Input X");
          countPressedButton ++;
      }
  }
Hope helps you.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                