Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Script that plays music while i press continuously a button

Discussion in 'Scripting' started by LatexBoy, May 18, 2019.

  1. LatexBoy

    LatexBoy

    Joined:
    May 12, 2019
    Posts:
    1
    Hello guys...i need a script or something like that with explications to play music when i press a button
    continuously. Like if i press continuously a button music plays and when i stop pressing the music will stop. Sorry for my bad english and please help!
     
  2. Dextozz

    Dextozz

    Joined:
    Apr 8, 2018
    Posts:
    62
    Code (CSharp):
    1.  void Update()
    2. {
    3.      if (Input.GetButtonDown("Fire1"))
    4.      {
    5.         //Play sound
    6.      }
    7.      else if(Input.GetButtonUp("Fire1"))
    8.      {
    9.         //Stop sound
    10.      }
    11. }