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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

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