Search Unity

InputManager only while held down?

Discussion in 'Scripting' started by Crazyman582, Sep 2, 2015.

  1. Crazyman582

    Crazyman582

    Joined:
    Aug 13, 2015
    Posts:
    13
    I'm trying to get it so that the gravity is set to 0 when the player holds the Fly key and back to normal when it is released. my code is

    // the fly state needs to read here to make sure it is not missed
    if (!m_Flying)
    {
    m_Flying = CrossPlatformInputManager.GetButtonDown("Fly");
    }

    if (m_Flying)
    {

    m_GravityMultiplier = 0;

    }

    This is in the FirstPersonController. I think this is a nooby question (i just started coding) but does anyone know how to do this?
     
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Code (csharp):
    1. m_Flying = CrossPlatformInputManager.GetButtonDown("Fly");
    2.          
    3. if (m_Flying) {
    4.     m_GravityMultiplier = 0;        
    5. } else  {
    6.     m_GravityMultiplier = 1;
    7. }
     
  3. Crazyman582

    Crazyman582

    Joined:
    Aug 13, 2015
    Posts:
    13
    Ah thank you! Suspected it was something stupid i wasnt doing