I jumbled a few Tutorials together for my first simple game.
I have 2 audio sources under my GameObject that I use as the character. They both play via "play on awake". Only one plays from script. The other either doesn’t sound at all or gives a few clicks when called from script.
I am using the most current Visual Studio to write Scripts
Here's a portion of my script that isn't working correctly (I have left out a lot of player movement script).
audio variable on line 7, audio play on line 33
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public Rigidbody rb;
public AudioSource AudioFall;
public GameObject Fall;
if(rb.position.y < -1f)
{
AudioFall.Play();
Fall.SetActive(true);
FindObjectOfType<GameManager>().GameOver();
}
Here is a portion in a separate .cs that is working
audio variable on line 7, audio play on line 17
using UnityEngine;
public class playerCollision : MonoBehaviour
{
public PlayerMovement movement;
public AudioSource AudioCrash;
public GameObject Crash;
void OnCollisionEnter(Collision collisionInfo)
{
if (collisionInfo.collider.tag == "Obstacle")
{
FindObjectOfType<PlayerMovement>().rb.isKinematic = true;
movement.enabled = false;
AudioCrash.Play();
Crash.SetActive(true);
FindObjectOfType<GameManager>().GameOver();
}
}
I have tried to increase max distance in the audiosource inspector.