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

How to call function (or corutine) like update if button pressed

Discussion in 'Input System' started by igorbukur2, Jan 1, 2020.

  1. igorbukur2

    igorbukur2

    Joined:
    Jan 1, 2020
    Posts:
    9
    How to call function (or corutine) like update func. if button pressed.
    I have corutine and start corutine from function. How in new input system call function like Update if i pressed ctrl button?

    I make Action (look screen.) But i don't know how it use.

    Code (CSharp):
    1. bool reload = false;
    2.  
    3. IEnumerator Shoot()
    4.     {
    5.         reload = true;
    6.         GameObject BulletG =  Instantiate(Bullet,SpawnPoint);
    7.  
    8.         yield return new WaitForSeconds(1f);
    9.         reload = false;
    10.     }
    11.  
    12.  
    13. public void StartShoot()
    14.     {
    15.         if (reload == false)
    16.         {
    17.             StartCoroutine(Shoot());
    18.         }
    19.     }
     
    Last edited: Jan 1, 2020
  2. igorbukur2

    igorbukur2

    Joined:
    Jan 1, 2020
    Posts:
    9
    On a simple: I want hold the CTRL and call every frame function StartShoot();
     
  3. NanushTol

    NanushTol

    Joined:
    Jan 9, 2018
    Posts:
    121
    is this what you need?
    YourInputClassName.YourActionsMap.YourAction.performed += context => StartShoot();