Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Set two controls to one input (read description)

Discussion in 'Scripting' started by Treasureman, Sep 24, 2014.

  1. Treasureman

    Treasureman

    Joined:
    Jul 5, 2014
    Posts:
    563
    So I'm making a shooter and ny controls are "joystick button 6" is aim and "joystick button 7" is melee. But when you use "joystick button 6" + "joystick button 7" I want it to shoot. How do I do this

    P.S. Resident Evil 6 uses the same thing if you want an example
     
  2. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    Make 2 Inputs, one for aiming and one for shooting.
    Test if the aimbutton is pressed and the shooting button is pressed on the same time.

    Code (CSharp):
    1.         if(Mathf.Approximately(Input.GetAxis("Aim"),1f))
    2.         {
    3.             //Do aim stuff
    4.         }
    5.  
    6.  
    7.         if(Mathf.Approximately(Input.GetAxis("Aim"),1f) && Mathf.Approximately(Input.GetAxis("Fire"),1f))
    8.         {
    9.             //Do shooting stuff
    10.         }
     
  3. A.Killingbeck

    A.Killingbeck

    Joined:
    Feb 21, 2014
    Posts:
    483
    Why the extra if check for Aim? It's not needed
     
  4. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    If you do not have anything todo if the user is aiming just ignore the first part.
     
  5. A.Killingbeck

    A.Killingbeck

    Joined:
    Feb 21, 2014
    Posts:
    483
    Not 100% sure what you mean, but this is what I meant:

    Code (CSharp):
    1. if(Mathf.Approximately(Input.GetAxis("Aim"),1f)
    2. {
    3.      if(Mathf.Approximately(Input.GetAxis("Fire"),1f))
    4.         {
    5.             //Do shooting stuff
    6.         }
    7.         else
    8.        {
    9.            //Aim
    10.        }
    11. }
    Unless that's what you meant? Haha :)
     
  6. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    Jep, that's the smarter way to do this :)