Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Question Map Input to Xbox Controller --> Is there a way to toggle a Boolean without it flickering?

Discussion in 'Input System' started by raijy, Jun 30, 2020.

  1. raijy

    raijy

    Joined:
    Jan 26, 2018
    Posts:
    1
    Hello there (^_^),

    New to coding, Unity, and mapping input to Xbox controllers and hoping folks here can help.

    A teammate and I are trying to map input to Xbox controllers. Our movement (left joystick) and jump ("A" button) work just fine. When the player picks up a weapon or shield we want the player to be able to hit a button to ready their weapon (Y) or shield (B) for combat. At present, the player can kind of ready their weapon and shield with a button press but the objects flicker. They don't snap into position like when we map input to the keyboard. Below is the original code that we started with. Today we experimented with adding a coroutine. Had the same result. I don't have copy of the coroutine code because my teammate tossed it to start over.

    Also below is a quick video clip of what our flicker issues look like.
    FYI we're working in Unity.2019.4

    Any guidance is truly appreciated.

    Cheers.



    Code (CSharp):
    1.  if( (Input.GetKeyDown(KeyCode.Q) || Input.GetAxisRaw("Fire1") != 0))
    2.         {
    3.    
    4.  
    5.             //is there an active weapon
    6.             UnityEngine.Debug.Log("The active weapon is " + ActiveWeapon);
    7.  
    8.             if (ActiveWeapon != null)
    9.             {
    10.                 isWeaponAxisInUse = Input.GetAxisRaw("Fire1") != 1 ? true : false; //ActiveWeapon.IsReady = !ActiveWeapon.IsReady;
    11.  
    12.                 if (!isWeaponAxisInUse)
    13.                 {
    14.                     ActiveWeapon.ToggleWeaponState();
    15.  
    16.                 }
    17.             }