Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Audio Can't stop AudioSource

Discussion in 'Audio & Video' started by Trekko, Aug 8, 2019.

  1. Trekko

    Trekko

    Joined:
    Jan 24, 2018
    Posts:
    21
    Hi!
    I'm making a game and wanted to add sound when player walking and other sound when player riding horse. There is a script:
    Code (CSharp):
    1.             if (cc.isGrounded == true && cc.velocity.magnitude > 0.1f && cc.velocity.magnitude < runGretsen + 0.1 && GetComponent<AudioSource>().isPlaying == false)
    2.             {
    3.                 GetComponent<AudioSource>().PlayOneShot(walk);
    4.             }
    5.             else if (cc.isGrounded == true && cc.velocity.magnitude > runGretsen && GetComponent<AudioSource>().isPlaying == false)
    6.             {
    7.                 GetComponent<AudioSource>().PlayOneShot(run);
    8.             }
    But when player dismount horse still play sound of walking or running. I tried to use .Stop() but it's not work. How to stop this sound?