Created
August 21, 2017 19:18
-
-
Save WakkyFree/99bc0d0d7fea4ac37ff381134a873caf to your computer and use it in GitHub Desktop.
Unity script to enable sound effects when a bat hits a ball.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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