Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Unity script to enable sound effects when a bat hits a ball.
using UnityEngine;
using System.Collections;
public class SoundBat : MonoBehaviour {
private AudioSource audioSourceBat;
public AudioClip seBat;
// Use this for initialization
void Start () {
audioSourceBat = gameObject.GetComponent<AudioSource>();
}
// Update is called once per frame
void Update () {
}
void OnCollisionEnter(Collision collision) {
if (collision.gameObject.name == "Ball") {
audioSourceBat.PlayOneShot(seBat);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment