Wednesday, February 27, 2019

Unity 3d Play Sound full script by allunityscripts

Play Sound


using UnityEngine;
using System.Collections;

public class PlaySound : MonoBehaviour {

    public AudioClip SoundToPlay;
    public float Volume;
    AudioSource audio;
    public bool alreadyPlayed = false;
    void Start()
    {
        audio = GetComponent<AudioSource>();
    }

    void OnTriggerEnter()
    {
        if (!alreadyPlayed)
        {
            audio.PlayOneShot(SoundToPlay, Volume);
            alreadyPlayed = true;
        }
    }
}

No comments:

Post a Comment