Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by miracleforcemanga · May 21 at 03:07 PM · audioaudiosourceaudioclip

audio plays sometimes, then not others.

hi! My team is developing our first game for a game jam, that being a dungeon platformer, and we ran into a problem with our death sound. whenever we hit the spikes in the game, it plays. but when another sound plays like the coin sound, (which is just a bleep) it just doesn't play unless we wait.

any fix to this?

here's my player controller code if needed(sorry if it's messy, I'm both new to this, and in a hurry for the jam.)

 using UnityEngine;
 using System.Collections;
 using UnityEngine.SceneManagement;
 using TMPro;
 
 public class PlayerController2D : MonoBehaviour 
 {
 
 //Public Variables
     public float speed;
     public float jump;
 
     public float coinCount;
 
     public string currentScene;
 
     public string nextScene;
 
     public GameObject openDoor;
 
     public GameObject closedDoor;
 
     public GameObject doorTrigger;
 
     public TextMeshProUGUI countText;
 
     public AudioSource audioSource;
 
     public AudioClip JumpSound;
 
     public AudioClip collectSound;
 
     public AudioClip deathSound;
 
     public AudioClip doorOpenSound;
 
     //Private Variables
     private float moveVelocity;
     private bool grounded = true;
 
     void Start()
     {
         openDoor.gameObject.SetActive(false);
         doorTrigger.gameObject.SetActive(false);
 
         
 
         SetCountText();
     }
 
     void SetCountText()
     {
         countText.text = "Coins left: " + coinCount.ToString();
 
     }
 
     void Update () 
     {
         //Jumping
         if (Input.GetKeyDown (KeyCode.Space) || Input.GetKeyDown (KeyCode.UpArrow) || Input.GetKeyDown (KeyCode.Z) || Input.GetKeyDown (KeyCode.W)) 
         {
             if(grounded)
             {
                 GetComponent<Rigidbody2D> ().velocity = new Vector2 (GetComponent<Rigidbody2D> ().velocity.x, jump);
                 audioSource.PlayOneShot(JumpSound);
             }
         }
 
         moveVelocity = 0;
 
         //Left Right Movement
         if (Input.GetKey (KeyCode.LeftArrow) || Input.GetKey (KeyCode.A)) 
         {
             moveVelocity = -speed;
         }
         if (Input.GetKey (KeyCode.RightArrow) || Input.GetKey (KeyCode.D)) 
         {
             moveVelocity = speed;
         }
 
         GetComponent<Rigidbody2D> ().velocity = new Vector2 (moveVelocity, GetComponent<Rigidbody2D> ().velocity.y);
 
     }
     //Check if Grounded
     void OnCollisionEnter2D()
     {
         grounded = true;
     }
     void OnCollisionExit2D()
     {
         grounded = false;
     }
 
     //sets trigger functions in scene
    void OnTriggerEnter2D(Collider2D other)
     {
         if(other.gameObject.CompareTag("Pickup"))
         {
             other.gameObject.SetActive(false);
             coinCount -= 1;
             audioSource.PlayOneShot(collectSound);
 
             SetCountText();
 
             if(coinCount == 0)
             {
                 openDoor.gameObject.SetActive(true);
                 closedDoor.gameObject.SetActive(false);
                 doorTrigger.gameObject.SetActive(true);
                 audioSource.PlayOneShot(doorOpenSound);
             }
         }
         if(other.gameObject.CompareTag("Death"))
         {
             audioSource.PlayOneShot(deathSound);
             gameObject.SetActive(false);
             SceneManager.LoadScene(currentScene);
             
 
         }
 
         if(other.gameObject.CompareTag("DoorTrigger"))
         {
             SceneManager.LoadScene(nextScene);
         }
 
     }
 }

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image miracleforcemanga · May 22 at 04:12 AM 0
Share

Fixed it. Thanks to everyone who followed this question. for those who have this problem in the future, all I did was make a separate audio source called deathSource, set it as a public variable, then made the death sound go through that, so it didn't stop whenever another one was playing.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

221 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Pick Up Sound 0 Answers

Trying to use derive pitch and db from realtime microphone input 0 Answers

Audio Cutting Out Unexplainably 1 Answer

Audio not playing when conditions are met. 0 Answers

Why won't my second Audio Source play? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges