public class PlayAndStopSoundOnClick : MonoBehaviour {
void Start () {
}
void Update () {
if (Input.GetMouseButtonDown(0)){
Ray clkRay = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit rh;
if (Physics.Raycast(clkRay, out rh, 20)) {
GameObject target = rh.collider.gameObject;
if (target == this.gameObject) {
CriAtomSource atom_src = target.GetComponent<CriAtomSource>();
if (atom_src != null) {
CriAtomSource.Status status = atom_src.status;
if ((status == CriAtomSource.Status.Stop) || (status == CriAtomSource.Status.PlayEnd)) {
atom_src.Play();
} else {
atom_src.Stop();
}
}
}
}
}
}
}