Help with audio please

Updated on June 25, 2017 in [A] Audio
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
0 on June 25, 2017

I jumbled a few Tutorials for my first simple game, and i have been able to solve all the problems i ran in to, but this is driving me nuts. I googled similar problems already.

I have 2 audio sources under my GameObject that i use as the character. They both play fine on awake. One plays fine from script. The other either doesn’t sound or gives a few clicks when called from script.

Here is the Script that i use for the audio that wont work ( the audio that does work is identical on my collision script)

audio play on line 33

audio varible on line 7

  1. using UnityEngine;
  2. public class PlayerMovement : MonoBehaviour
  3. {
  4. public Rigidbody rb;
  5. public AudioSource AudioFall;
  6. public GameObject Fall;
  7. public float forwardForce = 2000f; // Using a variable to manipulate the movement physics allows more freedom than apply a constant force
  8. public float sidewaysForce = 800f;
  9. // Update is called once per frame. Unity prefers FixedUpdate to Update when manipulating physic (i.e. Rigidbody)
  10. void FixedUpdate ()
  11. {
  12. rb.AddForce(0, 0, forwardForce * Time.deltaTime); // Time.deltaTime basically alters the applyed force from happening
  13. // per frame, and makes it more like per second. this is to cater to
  14. // any speed of computer with your game.
  15. if ( Input.GetKey("d") )
  16. {
  17. rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
  18. }
  19. if (Input.GetKey("a"))
  20. {
  21. rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
  22. }
  23. if(rb.position.y < -1f)
  24. {
  25. AudioFall.Play();
  26. Fall.SetActive(true);
  27. FindObjectOfType<GameManager>().GameOver();
  28. }
  29. }
  30. }

Help please

  • Liked by
Reply