Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

How do I call an FMOD Studio Event Emitter instead of Audio Source

Discussion in 'Scripting' started by sijamaudio, Apr 16, 2015.

  1. sijamaudio

    sijamaudio

    Joined:
    Mar 24, 2015
    Posts:
    1
    Hey guys, I've been getting my head around integrating FMOD into Unity3D over the last few weeks and have hit a bit of a wall with the currently project I'm working on. I'm only just getting used to scripting so please excuse me if I use the wrong terminology! Bare with me.

    I have the NinjaSlasherX complete project from the asset store and I'm attempting to implement audio via FMOD. The current audio is controlled via a script "App Sound" which is attached to a prefab of the same name. The script is simply a public class containing each SFX as an Audio Source, which allows other scripts to call the relevant audio source when needed. I get that I could just replace the current audio assests with my own of the same name, but I want to make use of FMOD's multi sound modules and pitch randomisation.

    So....

    The trouble I'm having is with changing the player controller script to call an FMOD asset rather than the Audio Source already in there.

    Here are the 2 scripts I'm currently working with..

    The "AppSound" script attached the the "AppSound" Prefab...

    Code (CSharp):
    1. sing UnityEngine;
    2. using System.Collections;
    3.  
    4. public class AppSound : MonoBehaviour {
    5.  
    6.     // === 外部パラメータ ======================================
    7.     public static AppSound instance = null;
    8.  
    9.     // BGM
    10.     [System.NonSerialized] public zFoxSoundManager fm;
    11.     [System.NonSerialized] public AudioSource BGM_LOGO;
    12.     [System.NonSerialized] public AudioSource BGM_TITLE;
    13.     [System.NonSerialized] public AudioSource BGM_HISCORE;
    14.     [System.NonSerialized] public AudioSource BGM_HISCORE_RANKIN;
    15.     [System.NonSerialized] public AudioSource BGM_STAGEA;
    16.     [System.NonSerialized] public AudioSource BGM_STAGEB;
    17.     [System.NonSerialized] public AudioSource BGM_STAGEB_ROOMSAKURA;
    18.     [System.NonSerialized] public AudioSource BGM_BOSSA;
    19.     [System.NonSerialized] public AudioSource BGM_BOSSB;
    20.     [System.NonSerialized] public AudioSource BGM_ENDING;
    21.  
    22.     // SE
    23.     [System.NonSerialized] public AudioSource SE_MENU_OK;
    24.     [System.NonSerialized] public AudioSource SE_MENU_CANCEL;
    25.  
    26.     [System.NonSerialized] public AudioSource SE_ATK_A1;
    27.     [System.NonSerialized] public AudioSource SE_ATK_A2;
    28.     [System.NonSerialized] public AudioSource SE_ATK_A3;
    29.     [System.NonSerialized] public AudioSource SE_ATK_B1;
    30.     [System.NonSerialized] public AudioSource SE_ATK_B2;
    31.     [System.NonSerialized] public AudioSource SE_ATK_B3;
    32.     [System.NonSerialized] public AudioSource SE_ATK_ARIAL;
    33.     [System.NonSerialized] public AudioSource SE_ATK_SYURIKEN;
    34.  
    35.     [System.NonSerialized] public AudioSource SE_HIT_A1;
    36.     [System.NonSerialized] public AudioSource SE_HIT_A2;
    37.     [System.NonSerialized] public AudioSource SE_HIT_A3;
    38.     [System.NonSerialized] public AudioSource SE_HIT_B1;
    39.     [System.NonSerialized] public AudioSource SE_HIT_B2;
    40.     [System.NonSerialized] public AudioSource SE_HIT_B3;
    41.  
    42.     [System.NonSerialized] public AudioSource SE_MOV_JUMP;
    43.  
    44.     [System.NonSerialized] public AudioSource SE_ITEM_KOBAN;
    45.     [System.NonSerialized] public AudioSource SE_ITEM_HYOUTAN;
    46.     [System.NonSerialized] public AudioSource SE_ITEM_MAKIMONO;
    47.     [System.NonSerialized] public AudioSource SE_ITEM_OHBAN;
    48.     [System.NonSerialized] public AudioSource SE_ITEM_KEY;
    49.  
    50.     [System.NonSerialized] public AudioSource SE_OBJ_EXIT;
    51.     [System.NonSerialized] public AudioSource SE_OBJ_OPENDOOR;
    52.     [System.NonSerialized] public AudioSource SE_OBJ_SWITCH;
    53.     [System.NonSerialized] public AudioSource SE_OBJ_BOXBROKEN;
    54.  
    55.     [System.NonSerialized] public AudioSource SE_CHECKPOINT;
    56.     [System.NonSerialized] public AudioSource SE_EXPLOSION;
    57.  
    58.     // === 内部パラメータ ======================================
    59.     string sceneName = "non";
    60.  
    61.     // === コード =============================================
    62.     void Awake () {
    63.         // Sound
    64.         fm = GameObject.Find("zFoxSoundManager").GetComponent<zFoxSoundManager>();
    65.  
    66.         // BGM
    67.         fm.CreateGroup("BGM");
    68.         fm.SoundFolder = "Sounds/BGM/";
    69.         BGM_LOGO                 = fm.LoadResourcesSound("BGM","Logo");
    70.         BGM_TITLE                 = fm.LoadResourcesSound("BGM","Title");
    71.         BGM_HISCORE             = fm.LoadResourcesSound("BGM","HiScore");
    72.         BGM_HISCORE_RANKIN         = fm.LoadResourcesSound("BGM","HiScore_Rankin");
    73.         BGM_STAGEA                 = fm.LoadResourcesSound("BGM","StageA");
    74.         BGM_STAGEB                 = fm.LoadResourcesSound("BGM","StageB");
    75.         BGM_STAGEB_ROOMSAKURA     = fm.LoadResourcesSound("BGM","StageB_RoomSakura");
    76.         BGM_BOSSA                 = fm.LoadResourcesSound("BGM","BossA");
    77.         BGM_BOSSB                 = fm.LoadResourcesSound("BGM","BossB");
    78.         BGM_ENDING                = fm.LoadResourcesSound("BGM","Ending");
    79.  
    80.         // SE
    81.         fm.CreateGroup("SE");
    82.         fm.SoundFolder = "Sounds/SE/";
    83.         SE_MENU_OK                 = fm.LoadResourcesSound("SE","SE_Menu_Ok");
    84.         SE_MENU_CANCEL          = fm.LoadResourcesSound("SE","SE_Menu_Cancel");
    85.  
    86.         SE_ATK_A1                  = fm.LoadResourcesSound("SE","SE_ATK_A1");
    87.         SE_ATK_A2                  = fm.LoadResourcesSound("SE","SE_ATK_A2");
    88.         SE_ATK_A3                  = fm.LoadResourcesSound("SE","SE_ATK_A3");
    89.         SE_ATK_B1                  = fm.LoadResourcesSound("SE","SE_ATK_B1");
    90.         SE_ATK_B2                  = fm.LoadResourcesSound("SE","SE_ATK_B2");
    91.         SE_ATK_B3                  = fm.LoadResourcesSound("SE","SE_ATK_B3");
    92.         SE_ATK_ARIAL              = fm.LoadResourcesSound("SE","SE_ATK_Arial");
    93.         SE_ATK_SYURIKEN          = fm.LoadResourcesSound("SE","SE_ATK_Syuriken");
    94.  
    95.         SE_HIT_A1                  = fm.LoadResourcesSound("SE","SE_HIT_A1");
    96.         SE_HIT_A2                  = fm.LoadResourcesSound("SE","SE_HIT_A2");
    97.         SE_HIT_A3                  = fm.LoadResourcesSound("SE","SE_HIT_A3");
    98. #if xxx
    99.         SE_HIT_B1                  = fm.LoadResourcesSound("SE","SE_HIT_B1");
    100.         SE_HIT_B2                  = fm.LoadResourcesSound("SE","SE_HIT_B2");
    101.         SE_HIT_B3                  = fm.LoadResourcesSound("SE","SE_HIT_B3");
    102. #endif
    103.         SE_HIT_B1 = SE_HIT_A1;
    104.         SE_HIT_B2 = SE_HIT_A2;
    105.         SE_HIT_B3 = SE_HIT_A3;
    106.  
    107.         SE_MOV_JUMP              = fm.LoadResourcesSound("SE","SE_MOV_Jump");
    108.  
    109.         SE_ITEM_KOBAN            = fm.LoadResourcesSound("SE","SE_Item_Koban");
    110.         SE_ITEM_HYOUTAN            = fm.LoadResourcesSound("SE","SE_Item_Hyoutan");
    111.         SE_ITEM_MAKIMONO        = fm.LoadResourcesSound("SE","SE_Item_Makimono");
    112.         SE_ITEM_OHBAN            = fm.LoadResourcesSound("SE","SE_Item_Ohban");
    113.         SE_ITEM_KEY                = fm.LoadResourcesSound("SE","SE_Item_Key");
    114.  
    115.         SE_OBJ_EXIT                = fm.LoadResourcesSound("SE","SE_OBJ_Exit");
    116.         SE_OBJ_OPENDOOR            = fm.LoadResourcesSound("SE","SE_OBJ_OpenDoor");
    117.         SE_OBJ_SWITCH            = fm.LoadResourcesSound("SE","SE_OBJ_Switch");
    118.         SE_OBJ_BOXBROKEN        = fm.LoadResourcesSound("SE","SE_OBJ_BoxBroken");
    119.  
    120.         SE_CHECKPOINT            = fm.LoadResourcesSound("SE","SE_CheckPoint");
    121.         SE_EXPLOSION            = fm.LoadResourcesSound("SE","SE_Explosion");
    122.  
    123.         instance = this;
    124.     }
    125.  
    126.     void Update() {
    127.         // シーンチェンジをチェック
    128.         if (sceneName != Application.loadedLevelName) {
    129.             sceneName = Application.loadedLevelName;
    130.  
    131.             // ボリューム設定
    132.             fm.SetVolume("BGM",SaveData.SoundBGMVolume);
    133.             fm.SetVolume("SE" ,SaveData.SoundSEVolume);
    134.  
    135.             // BGM再生
    136.             if (sceneName == "Menu_Logo") {
    137.                 BGM_LOGO.Play();
    138.             } else
    139.             if (sceneName == "Menu_Title") {
    140.                 if (!BGM_TITLE.isPlaying) {
    141.                     fm.Stop ("BGM");
    142.                     BGM_TITLE.Play();
    143.                     fm.FadeInVolume(BGM_TITLE,SaveData.SoundBGMVolume,1.0f,true);
    144.                 }
    145.             } else
    146.             if (sceneName == "Menu_Option"  ||
    147.                 sceneName == "Menu_HiScore" ||
    148.                 sceneName == "Menu_Option") {
    149.             } else
    150.             if (sceneName == "StageA") {
    151.                 //fm.Stop ("BGM");
    152.                 fm.FadeOutVolumeGroup("BGM",BGM_STAGEA,0.0f,1.0f,false);
    153.                 fm.FadeInVolume(BGM_TITLE,SaveData.SoundBGMVolume,1.0f,true);
    154.                 BGM_STAGEA.loop = true;
    155.                 BGM_STAGEA.Play();
    156.             } else
    157.             if (sceneName == "StageB_Room") {
    158.                 fm.Stop ("BGM");
    159.                 BGM_STAGEB_ROOMSAKURA.loop = true;
    160.                 BGM_STAGEB_ROOMSAKURA.Play();
    161.             } else
    162.             if (sceneName == "StageB_Room_A" ||
    163.                 sceneName == "StageB_Room_B" ||
    164.                 sceneName == "StageB_Room_C") {
    165.                 fm.Stop ("BGM");
    166.                 BGM_BOSSA.loop = true;
    167.                 BGM_BOSSA.Play();
    168.             } else
    169.             if (sceneName == "StageB_Boss") {
    170.                 fm.Stop ("BGM");
    171.                 BGM_BOSSB.loop = true;
    172.                 BGM_BOSSB.Play();
    173.             } else
    174.             if (sceneName == "StageZ_Ending") {
    175.                 fm.Stop ("BGM");
    176.                 BGM_ENDING.Play();
    177.             } else {
    178.                 if (!BGM_STAGEB.isPlaying) {
    179.                     fm.Stop ("BGM");
    180.                     BGM_STAGEB.loop = true;
    181.                     BGM_STAGEB.Play();
    182.                 }
    183.             }
    184.         }
    185.     }
    186. }
    187.  


    And the player controller which I'm assuming is calling the AudioSources via animations? Found on lines 179-184



    Code (CSharp):
    1. ing UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerController : BaseCharacterController {
    5.  
    6.     // === 外部パラメータ(インスペクタ表示) =====================
    7.                          public float     initHpMax = 20.0f;
    8.     [Range(0.1f,100.0f)] public float     initSpeed = 12.0f;
    9.  
    10.     // === 外部パラメータ ======================================
    11.     // セーブデータパラメータ
    12.     public static    float         nowHpMax                 = 0;
    13.     public static    float         nowHp                       = 0;
    14.     public static     int            score                     = 0;
    15.    
    16.     public static     bool         checkPointEnabled         = false;
    17.     public static     string        checkPointSceneName     = "";
    18.     public static     string        checkPointLabelName     = "";
    19.     public static    float         checkPointHp             = 0;
    20.    
    21.     public static     bool         itemKeyA                = false;
    22.     public static     bool         itemKeyB                 = false;
    23.     public static     bool         itemKeyC                 = false;
    24.  
    25.     // 外部からの処理操作用パラメータ
    26.     public static     bool        initParam                   = true;
    27.     public static     float        startFadeTime             = 2.0f;
    28.    
    29.     // 基本パラメータ
    30.     [System.NonSerialized] public float        groundY     = 0.0f;
    31.     [System.NonSerialized] public bool        superMode    = false;
    32.  
    33.     [System.NonSerialized] public int         comboCount    = 0;
    34.  
    35.     [System.NonSerialized] public Vector3     enemyActiveZonePointA;
    36.     [System.NonSerialized] public Vector3     enemyActiveZonePointB;
    37.  
    38.     // アニメーションのハッシュ名
    39.     public readonly static int ANISTS_Idle              = Animator.StringToHash("Base Layer.Player_Idle");
    40.     public readonly static int ANISTS_Walk              = Animator.StringToHash("Base Layer.Player_Walk");
    41.     public readonly static int ANISTS_Run               = Animator.StringToHash("Base Layer.Player_Run");
    42.     public readonly static int ANISTS_Jump              = Animator.StringToHash("Base Layer.Player_Jump");
    43.     public readonly static int ANISTS_ATTACK_A         = Animator.StringToHash("Base Layer.Player_ATK_A");
    44.     public readonly static int ANISTS_ATTACK_B         = Animator.StringToHash("Base Layer.Player_ATK_B");
    45.     public readonly static int ANISTS_ATTACK_C         = Animator.StringToHash("Base Layer.Player_ATK_C");
    46.     public readonly static int ANISTS_ATTACKJUMP_A  = Animator.StringToHash("Base Layer.Player_ATKJUMP_A");
    47.     public readonly static int ANISTS_ATTACKJUMP_B  = Animator.StringToHash("Base Layer.Player_ATKJUMP_B");
    48.     public readonly static int ANISTS_DEAD          = Animator.StringToHash("Base Layer.Player_Dead");
    49.  
    50.     // === キャッシュ ==========================================
    51.     LineRenderer    hudHpBar;
    52.     TextMesh        hudScore;
    53.     TextMesh         hudCombo;
    54.  
    55.     // === 内部パラメータ ======================================
    56.     int             jumpCount            = 0;
    57.  
    58.     volatile bool     atkInputEnabled        = false;
    59.     volatile bool    atkInputNow            = false;
    60.  
    61.     bool            breakEnabled        = true;
    62.     float             groundFriction        = 0.0f;
    63.  
    64.     float             comboTimer             = 0.0f;
    65.    
    66.  
    67.     // === コード(サポート関数) ===============================
    68.     public static GameObject GetGameObject() {
    69.         return GameObject.FindGameObjectWithTag ("Player");
    70.     }
    71.     public static Transform GetTranform() {
    72.         return GameObject.FindGameObjectWithTag ("Player").transform;
    73.     }
    74.     public static PlayerController GetController() {
    75.         return GameObject.FindGameObjectWithTag ("Player").GetComponent<PlayerController>();
    76.     }
    77.     public static Animator GetAnimator() {
    78.         return GameObject.FindGameObjectWithTag ("Player").GetComponent<Animator>();
    79.     }
    80.  
    81.     // === コード(Monobehaviour基本機能の実装) ================
    82.     protected override void Awake () {
    83.         base.Awake ();
    84.  
    85.         #if xxx
    86.         Debug.Log (">>> ANISTS_Idle : " + ANISTS_Idle);
    87.         Debug.Log (">>> ANISTS_Walk : " + ANISTS_Walk);
    88.         Debug.Log (">>> ANISTS_Run : " + ANISTS_Run);
    89.         Debug.Log (">>> ANISTS_Jump : " + ANISTS_Jump);
    90.         Debug.Log (">>> ANITAG_ATTACK_A : " + ANISTS_ATTACK_A);
    91.         Debug.Log (">>> ANITAG_ATTACK_B : " + ANISTS_ATTACK_B);
    92.         Debug.Log (">>> ANITAG_ATTACK_C : " + ANISTS_ATTACK_C);
    93.         Debug.Log(string.Format("0 -> {0}",playerAnim.GetLayerName (0)));
    94.         Debug.Log(string.Format("1 -> {0}",playerAnim.GetLayerName (1)));
    95.         #endif
    96.  
    97.         // !!! ガベコレ強制実行 !!!
    98.         System.GC.Collect ();
    99.         // !!!!!!!!!!!!!!!!!!!!!
    100.  
    101.         // キャッシュ
    102.         hudHpBar         = GameObject.Find ("HUD_HPBar").GetComponent<LineRenderer> ();
    103.         hudScore         = GameObject.Find ("HUD_Score").GetComponent<TextMesh> ();
    104.         hudCombo         = GameObject.Find ("HUD_Combo").GetComponent<TextMesh> ();
    105.  
    106.         // パラメータ初期化
    107.         speed             = initSpeed;
    108.         groundY         = groundCheck_C.transform.position.y + 2.0f;
    109.  
    110.         // アクティブゾーンをBoxCollider2Dから取得
    111.         BoxCollider2D boxCol2D = transform.Find("Collider_EnemyActiveZone").GetComponent<BoxCollider2D>();
    112.         enemyActiveZonePointA = new Vector3 (boxCol2D.offset.x - boxCol2D.size.x / 2.0f, boxCol2D.offset.y - boxCol2D.size.y / 2.0f);
    113.         enemyActiveZonePointB = new Vector3 (boxCol2D.offset.x + boxCol2D.size.x / 2.0f, boxCol2D.offset.y + boxCol2D.size.y / 2.0f);
    114.         boxCol2D.transform.gameObject.SetActive(false);
    115.  
    116.         // コンティニューチェック
    117.         if (SaveData.continuePlay) {
    118.             // コンティニュー
    119.             if (!SaveData.LoadGamePlay (true)) {
    120.                 initParam = false;
    121.             }
    122.             SaveData.continuePlay  = false;
    123.         }
    124.         if (initParam) {
    125.             // ニュー(初めからプレイ)
    126.             SetHP(initHpMax,initHpMax);
    127.             PlayerController.score = 0;
    128.             PlayerController.checkPointEnabled   = false;
    129.             PlayerController.checkPointLabelName = "";
    130.             PlayerController.checkPointSceneName = Application.loadedLevelName;
    131.             PlayerController.checkPointHp          = initHpMax;
    132.             PlayerController.itemKeyA              = false;
    133.             PlayerController.itemKeyB              = false;
    134.             PlayerController.itemKeyC              = false;
    135.             SaveData.DeleteAndInit(false);
    136.             SaveData.SaveGamePlay ();
    137.             initParam = false;
    138.         } else {
    139.             // コンティニューでもニューでもないリンクからのジャンプの場合は
    140.             // ステージの状態だけをセーブデータからロードする
    141.             SaveData.LoadGamePlay (false);
    142.         }
    143.         if (SetHP(PlayerController.nowHp,PlayerController.nowHpMax)) {
    144.             // HPがない場合は1からスタート
    145.             SetHP(1,initHpMax);
    146.         }
    147.  
    148.         // チェックポイントからの再開
    149.         if (checkPointEnabled) {
    150.             StageTrigger_CheckPoint[] triggerList = GameObject.Find("Stage").GetComponentsInChildren<StageTrigger_CheckPoint>();
    151.             foreach(StageTrigger_CheckPoint trigger in triggerList) {
    152.                 if (trigger.labelName == checkPointLabelName) {
    153.                     transform.position = trigger.transform.position;
    154.                     groundY = transform.position.y;
    155.                     Camera.main.GetComponent<CameraFollow>().SetCamera(trigger.cameraParam);
    156.                     break;
    157.                 }
    158.             }
    159.         }
    160.         Camera.main.transform.position = new Vector3(transform.position.x,
    161.                                                      groundY,
    162.                                                      Camera.main.transform.position.z);
    163.  
    164.         // Virtual Pad,HUD表示状態を設定
    165.         GameObject.Find ("VRPad").SetActive (SaveData.VRPadEnabled);
    166.  
    167.         Transform hud = GameObject.FindGameObjectWithTag ("SubCamera").transform;
    168.         hud.Find("Stage_Item_Key_A").GetComponent<SpriteRenderer>().enabled = itemKeyA;
    169.         hud.Find("Stage_Item_Key_B").GetComponent<SpriteRenderer>().enabled = itemKeyB;
    170.         hud.Find("Stage_Item_Key_C").GetComponent<SpriteRenderer>().enabled = itemKeyC;
    171.     }
    172.  
    173.     protected override void Start() {
    174.         base.Start ();
    175.  
    176.         zFoxFadeFilter.instance.FadeIn (Color.black, startFadeTime);
    177.         startFadeTime = 2.0f;
    178.  
    179.         seAnimationList = new AudioSource[5];
    180.         seAnimationList [0] = AppSound.instance.SE_ATK_A1;
    181.         seAnimationList [1] = AppSound.instance.SE_ATK_A2;
    182.         seAnimationList [2] = AppSound.instance.SE_ATK_A3;
    183.         seAnimationList [3] = AppSound.instance.SE_ATK_ARIAL;
    184.         seAnimationList [4] = AppSound.instance.SE_MOV_JUMP;
    185.     }
    186.  
    187.  
    188.     int hudScoreNum = -1;
    189.  
    190.     protected override void Update () {
    191.         base.Update ();
    192.  
    193.         // ステータス表示
    194.         hudHpBar.SetPosition (1, new Vector3 (5.0f * (hp / hpMax), 0.0f, 0.0f));
    195.         if (hudScoreNum != score) {
    196.             hudScore.text = string.Format("Score {0}",score);
    197.             hudScoreNum = score;
    198.         }
    199.  
    200.         if (comboTimer <= 0.0f) {
    201.             hudCombo.gameObject.SetActive(false);
    202.             comboCount = 0;
    203.             comboTimer = 0.0f;
    204.         } else {
    205.             comboTimer -= Time.deltaTime;
    206.             if (comboTimer > 5.0f) {
    207.                 comboTimer = 5.0f;
    208.             }
    209.             float s = 0.3f + 0.5f * comboTimer;
    210.             hudCombo.gameObject.SetActive(true);
    211.             hudCombo.transform.localScale = new Vector3(s,s,1.0f);
    212.         }
    213.  
    214. #if xxx
    215.         // Debug
    216.         BoxCollider2D boxCol2D = GameObject.Find("Collider_EnemyActiveZone").GetComponent<BoxCollider2D>();
    217.         Vector3 vecA = transform.position + new Vector3 (boxCol2D.center.x - boxCol2D.size.x / 2.0f, boxCol2D.center.y - boxCol2D.size.y / 2.0f);
    218.         Vector3 vecB = transform.position + new Vector3 (boxCol2D.center.x + boxCol2D.size.x / 2.0f, boxCol2D.center.y + boxCol2D.size.y / 2.0f);
    219.         Collider2D[] col2DList = Physics2D.OverlapAreaAll (vecA,vecB);
    220.         foreach(Collider2D col2D in col2DList) {
    221.             if (col2D.tag == "EnemyBody") {
    222.                 col2D.GetComponentInParent<EnemyMain>().cameraEnabled = true;
    223.             }
    224.         }
    225. #endif      
    226.     }
    227.  
    228.     protected override void FixedUpdateCharacter () {
    229.         // 現在のステートを取得
    230.         AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);
    231.  
    232.         // 着地チェック
    233.         if (jumped) {
    234.             if ((grounded && !groundedPrev) ||
    235.                 (grounded && Time.fixedTime > jumpStartTime + 1.0f)) {
    236.                 animator.SetTrigger ("Idle");
    237.                 jumped       = false;
    238.                 jumpCount = 0;
    239.                 GetComponent<Rigidbody2D>().gravityScale = gravityScale;
    240.             }
    241.             if (Time.fixedTime > jumpStartTime + 1.0f) {
    242.                 if (stateInfo.nameHash == ANISTS_Idle || stateInfo.nameHash == ANISTS_Walk ||
    243.                     stateInfo.nameHash == ANISTS_Run  || stateInfo.nameHash == ANISTS_Jump) {
    244.                     GetComponent<Rigidbody2D>().gravityScale = gravityScale;
    245.                 }
    246.             }
    247.         } else {
    248.             jumpCount = 0;
    249.             GetComponent<Rigidbody2D>().gravityScale = gravityScale;
    250.         }
    251.  
    252.         // 攻撃中か?
    253.         if (stateInfo.nameHash == ANISTS_ATTACK_A ||
    254.             stateInfo.nameHash == ANISTS_ATTACK_B ||
    255.             stateInfo.nameHash == ANISTS_ATTACK_C ||
    256.             stateInfo.nameHash == ANISTS_ATTACKJUMP_A ||
    257.             stateInfo.nameHash == ANISTS_ATTACKJUMP_B) {
    258.             // 移動停止
    259.             speedVx = 0;
    260.         }
    261.  
    262. #if xxx
    263.         // キャラの方向(攻撃中やジャンプ中に振り向き禁止にする)
    264.         if (stateInfo.nameHash != ANISTS_ATTACK_A &&
    265.             stateInfo.nameHash != ANISTS_ATTACK_B &&
    266.             stateInfo.nameHash != ANISTS_ATTACK_C &&
    267.             stateInfo.nameHash != ANISTS_ATTACKJUMP_A &&
    268.             stateInfo.nameHash != ANISTS_ATTACKJUMP_B) {
    269.             transform.localScale = new Vector3 (basScaleX * dir, transform.localScale.y, transform.localScale.z);
    270.         }
    271. #else
    272.         // キャラの方向
    273.         transform.localScale = new Vector3 (basScaleX * dir, transform.localScale.y, transform.localScale.z);
    274. #endif
    275.  
    276.         // ジャンプ中の横移動減速
    277.         if (jumped && !grounded && groundCheck_OnMoveObject == null) {
    278.             if (breakEnabled) {
    279.                 breakEnabled = false;
    280.                 speedVx *= 0.9f;
    281.             }
    282.         }
    283.  
    284.         // 移動停止(減速)処理
    285.         if (breakEnabled) {
    286.             speedVx *= groundFriction;
    287.         }
    288.     }
    289.  
    290.     // === コード(アニメーションイベント用コード) ===============
    291.     public void EnebleAttackInput() {
    292.         atkInputEnabled = true;
    293.     }
    294.    
    295.     public void SetNextAttack(string name) {
    296.         if (atkInputNow == true) {
    297.             atkInputNow = false;
    298.             animator.Play(name);
    299.         }
    300.     }
    301.  
    302.     // === コード(基本アクション) =============================
    303.     public override void ActionMove(float n) {
    304.         if (!activeSts) {
    305.             return;
    306.         }
    307.  
    308.         // 初期化
    309.         float dirOld = dir;
    310.         breakEnabled = false;
    311.  
    312.         // アニメーション指定
    313.         float moveSpeed = Mathf.Clamp(Mathf.Abs (n),-1.0f,+1.0f);
    314.         animator.SetFloat("MovSpeed",moveSpeed);
    315.         //animator.speed = 1.0f + moveSpeed;
    316.  
    317.         // 移動チェック
    318.         if (n != 0.0f) {
    319.             // 移動
    320.             dir       = Mathf.Sign(n);
    321.             moveSpeed = (moveSpeed < 0.5f) ? (moveSpeed * (1.0f / 0.5f)) : 1.0f;
    322.             speedVx   = initSpeed * moveSpeed * dir;
    323.         } else {
    324.             // 移動停止
    325.             breakEnabled = true;
    326.         }
    327.  
    328.         // その場振り向きチェック
    329.         if (dirOld != dir) {
    330.             breakEnabled = true;
    331.         }
    332.     }
    333.  
    334.     public void ActionJump() {
    335.         AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);
    336.         if (stateInfo.nameHash == ANISTS_Idle || stateInfo.nameHash == ANISTS_Walk || stateInfo.nameHash == ANISTS_Run ||
    337.             (stateInfo.nameHash == ANISTS_Jump && GetComponent<Rigidbody2D>().gravityScale >= gravityScale)) {
    338.             switch(jumpCount) {
    339.             case 0 :
    340.                 if (grounded) {
    341.                     animator.SetTrigger ("Jump");
    342.                     //rigidbody2D.AddForce (new Vector2 (0.0f, 1500.0f));    // Bug
    343.                     GetComponent<Rigidbody2D>().velocity = Vector2.up * 30.0f;
    344.                     jumpStartTime = Time.fixedTime;
    345.                     jumped = true;
    346.                     jumpCount ++;
    347.                 }
    348.                 break;
    349.             case 1 :
    350.                 if (!grounded) {
    351.                     animator.Play("Player_Jump",0,0.0f);
    352.                     GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x,20.0f);
    353.                     jumped = true;
    354.                     jumpCount ++;
    355.                 }
    356.                 break;
    357.             }
    358.             //Debug.Log(string.Format("Jump 1 {0} {1} {2} {3}",jumped,transform.position,grounded,groundedPrev));
    359.             //Debug.Log(groundCheckCollider[1].name);
    360.             AppSound.instance.SE_MOV_JUMP.Play ();
    361.         }
    362.     }
    363.  
    364.     public void ActionAttack() {
    365.         AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);
    366.         if (stateInfo.nameHash == ANISTS_Idle || stateInfo.nameHash == ANISTS_Walk || stateInfo.nameHash == ANISTS_Run ||
    367.             stateInfo.nameHash == ANISTS_Jump || stateInfo.nameHash == ANISTS_ATTACK_C) {
    368.  
    369.             animator.SetTrigger ("Attack_A");
    370.             if (stateInfo.nameHash == ANISTS_Jump || stateInfo.nameHash == ANISTS_ATTACK_C) {
    371.                 GetComponent<Rigidbody2D>().velocity     = new Vector2(0.0f,0.0f);
    372.                 GetComponent<Rigidbody2D>().gravityScale = 0.1f;
    373.             }
    374.         } else {
    375.             if (atkInputEnabled) {
    376.                 atkInputEnabled = false;
    377.                 atkInputNow     = true;
    378.             }
    379.         }
    380.     }
    381.  
    382.     public void ActionAttackJump() {
    383.         AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);
    384.         if (grounded &&
    385.             (stateInfo.nameHash == ANISTS_Idle || stateInfo.nameHash == ANISTS_Walk || stateInfo.nameHash == ANISTS_Run ||
    386.              stateInfo.nameHash == ANISTS_ATTACK_A || stateInfo.nameHash == ANISTS_ATTACK_B)) {
    387.             animator.SetTrigger ("Attack_C");
    388.             jumpCount = 2;
    389.         } else {
    390.             if (atkInputEnabled) {
    391.                 atkInputEnabled = false;
    392.                 atkInputNow     = true;
    393.             }
    394.         }
    395.     }
    396.  
    397.     public void ActionEtc() {
    398.         Collider2D[] otherAll = Physics2D.OverlapPointAll (groundCheck_C.position);
    399.         foreach (Collider2D other in otherAll) {
    400.             if (other.tag == "EventTrigger") {
    401.                 StageTrigger_Link link = other.GetComponent<StageTrigger_Link>();
    402.                 if (link != null) {
    403.                     link.Jump();
    404.                 }
    405.             } else
    406.             if (other.tag == "KeyDoor") {
    407.                 StageObject_KeyDoor keydoor = other.GetComponent<StageObject_KeyDoor>();
    408.                 keydoor.OpenDoor();
    409.             } else
    410.             if (other.name == "Stage_Switch_Body") {
    411.                 StageObject_Switch sw = other.transform.parent.GetComponent<StageObject_Switch>();
    412.                 sw.SwitchTurn();
    413.             }
    414.         }
    415.     }
    416.  
    417.     public void ActionDamage(float damage) {
    418.         // Debug:無敵モード
    419.         if (SaveData.debug_Invicible) {
    420.             return;
    421.         }
    422.         // ダメージ処理をしてもいいか?
    423.         if (!activeSts) {
    424.             return;
    425.         }
    426.  
    427. #if xxx
    428.         // ランダムにヒット音を再生
    429.         switch(Random.Range(0,3)) {
    430.         case 0 : AppSound.instance.SE_HIT_A1.Play (); break;
    431.         case 1 : AppSound.instance.SE_HIT_A2.Play (); break;
    432.         case 2 : AppSound.instance.SE_HIT_A3.Play (); break;
    433.         }
    434. #else
    435.         // ヒット音を再生
    436.         AppSound.instance.SE_HIT_A1.Play ();
    437. #endif
    438.  
    439. #if !UNITY_EDITOR && (UNITY_IPHONE || UNITY_ANDROID)
    440.         Handheld.Vibrate();
    441. #endif
    442.  
    443.         animator.SetTrigger ("DMG_A");
    444.         speedVx = 0;
    445.         GetComponent<Rigidbody2D>().gravityScale = gravityScale;
    446.  
    447.         // Combo Reset
    448.         comboCount = 0;
    449.         comboTimer = 0.0f;
    450.  
    451.         if (jumped) {
    452.             damage *= 1.5f;
    453.         }
    454.  
    455.         if (SetHP(hp - damage,hpMax)) {
    456.             Dead(true); // 死亡
    457.         }
    458.     }
    459.  
    460.     // === コード(その他) ====================================
    461.     public override void Dead(bool gameOver) {
    462.         // 死亡処理をしてもいいか?
    463.         AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);
    464.         if (!activeSts || stateInfo.nameHash == ANISTS_DEAD) {
    465.             return;
    466.         }
    467.  
    468.         base.Dead (gameOver);
    469.  
    470.         zFoxFadeFilter.instance.FadeOut (Color.black, 2.0f);
    471.  
    472.         if (gameOver) {
    473.             SetHP(0,hpMax);
    474.             Invoke ("GameOver", 3.0f);
    475.         } else {
    476.             SetHP(hp / 2,hpMax);
    477.             Invoke ("GameReset", 3.0f);
    478.         }
    479.  
    480.         GameObject.Find ("HUD_Dead").GetComponent<MeshRenderer> ().enabled = true;
    481.         GameObject.Find ("HUD_DeadShadow").GetComponent<MeshRenderer> ().enabled = true;
    482.         if (GameObject.Find ("VRPad") != null) {
    483.             GameObject.Find ("VRPad").SetActive(false);
    484.         }
    485.     }
    486.  
    487.     public void GameOver() {
    488.         SaveData.SaveHiScore(score);
    489.         PlayerController.score = 0;
    490.         PlayerController.nowHp = PlayerController.checkPointHp;
    491.         SaveData.SaveGamePlay ();
    492.  
    493.         AppSound.instance.fm.Stop ("BGM");
    494.         if (SaveData.newRecord > 0) {
    495.             AppSound.instance.BGM_HISCORE_RANKIN.Play ();
    496.         } else {
    497.             AppSound.instance.BGM_HISCORE.Play ();
    498.         }
    499.  
    500.         Application.LoadLevel("Menu_HiScore");
    501.     }
    502.  
    503.     void GameReset() {
    504.         SaveData.SaveGamePlay ();
    505.         Application.LoadLevel(Application.loadedLevelName);
    506.     }
    507.  
    508.     public override bool SetHP(float _hp,float _hpMax) {
    509.         if (_hp > _hpMax) {
    510.             _hp = _hpMax;
    511.         }
    512.         nowHp         = _hp;
    513.         nowHpMax     = _hpMax;
    514.         return base.SetHP (_hp, _hpMax);
    515.     }
    516.  
    517.     public void AddCombo() {
    518.         comboCount ++;
    519.         comboTimer += 1.0f;
    520.         hudCombo.text = string.Format("Combo {0}",comboCount);
    521.     }
    522. }
    523.  
    So I guess untimely I'd like to create a new prefab with FMOD_Studio_Event_Emitter's attached to it, and have other scrips call these instead of the current AudioSource's. Is this possible? In other projects I've used "Get Component" to call FMOD assets, but they were attached to the actual "Player Controller" Script, I'm unsure of how this would work when they are calling sounds from a Prefab.

    Thanks in advance for any help, I'd much appreciate it!

    Apologies also if there was no need to post the entirety of the scripts, I'm unsure if the whole thing was needed!