| ミドルウェア | CRI ADX2 (CRI Atom) |
| サンプル | Scriptサンプル:クリック&プレイ |
| 格納場所 | /cri/unity/samples/UnityProject/Assets/Scenes/criatom/script/ScriptSample01_ClickToPlay/Scenes |
| シーンファイル | ScriptSample01_scene_ClickToPlay.unity |
| ADX2データのオリジナル | データ:ピンボール |
public class PlaySoundOnClick : MonoBehaviour { private bool trigger = false; void Start () { } void Update () { if (trigger) { CriAtomSource atomSrc = gameObject.GetComponent<CriAtomSource>(); if (atomSrc != null) { atomSrc.Play(); } trigger = false; } } void OnGUI() { if (Scene_00_SampleList.ShowList == true) { return; } if (Camera.main == null) { return; } Scene_00_GUI.BeginGui("01/SampleMain1"); /* Set UI skin. */ GUI.skin = Scene_00_SampleList.uiSkin; var pos = Camera.main.WorldToScreenPoint(transform.position); pos.y = Screen.height - pos.y; if (Scene_00_GUI.Button(new Rect(pos.x, pos.y, 150, 150), "Play")) { trigger = true; } Scene_00_GUI.EndGui(); } }
public class PlayAndStopSoundOnClick : MonoBehaviour { private bool trigger = false; void Start () { } void Update () { if (trigger) { CriAtomSource atomSrc = gameObject.GetComponent<CriAtomSource>(); if (atomSrc != null) { CriAtomSource.Status status = atomSrc.status; if ((status == CriAtomSource.Status.Stop) || (status == CriAtomSource.Status.PlayEnd)) { atomSrc.Play(); } else { atomSrc.Stop(); } } trigger = false; } } void OnGUI() { if (Scene_00_SampleList.ShowList == true) { return; } if (Camera.main == null) { return; } Scene_00_GUI.BeginGui("01/SampleMain2"); /* Set UI skin. */ GUI.skin = Scene_00_SampleList.uiSkin; var pos = Camera.main.WorldToScreenPoint(transform.position); pos.y = Screen.height - pos.y; if (Scene_00_GUI.Button(new Rect(pos.x, pos.y, 150, 150), "Play/Stop")) { trigger = true; } Scene_00_GUI.EndGui(); } }