Home>
Troubleshooting

My function seems to be called, but there is no sound.

Environment

Unity2018 2.4f1

Source code
// GameManager.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
public class BatteryChecker: MonoBehaviour {
    bool state = false;
    int lockint = 0;// unlock = 0 lock = 1
    public GameObject Button;
    public GameObject GameManager;
    public GameObject VoiceManager;
    int toutyaku = 0;
    int BatteryFull = 0;

    // Update is called once per frame
    void Update ()
    {
        string bstatus = string.Format ("{0}", SystemInfo.batteryStatus);
        if (bstatus == "Charging"&&state == false) // Key is ON
        {
            state = true;
            Debug.Log ("The key ON !!!!");
            GameManager.GetComponent<GameManager>(). ButtonDestroy ();//
            Debug.Log ("Departure!");
            toutyaku = 1;
        }
        if (bstatus == "Discharging"&&toutyaku == 1) // arrival
        {
            toutyaku = 0;
            VoiceManager.GetComponent<VoiceManager>(). ArrivedVoice ();
            GameManager.GetComponent<GameManager>(). InstantiateButton ();
            Debug.Log ("arrival");
        }
        if (bstatus == "Full"&&BatteryFull == 0&&state == true) // Battery full charge
        {
            BatteryFull = 1;// Reset on arrival
            DOVirtual.DelayedCall (30.0f, () =>
            {
                VoiceManager.GetComponent<VoiceManager>(). BatteryFullChargeVoice ();
            });
        }
    }
    public void Deperture ()
    {
        state = true;
        Debug.Log ("The key ON !!!!");
        GameManager.GetComponent<GameManager>(). ButtonDestroy ();
        Debug.Log ("Departure!");
    }
    public void Arrive ()
    {
        VoiceManager.GetComponent<VoiceManager>(). ArrivedVoice ();
        GameManager.GetComponent<GameManager>(). InstantiateButton ();
    }
}
/VoiceManager.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class VoiceManager: MonoBehaviour {
    public float SumTime;
    public float RestTime;
    public float RandomTime;
    public float RTempTime;
    public bool lockbool = false;// TRUE only while running. False if you do not want to sound
    public int moddd;
    // Attendance 1 Retirement 2 Rest bound 3 Rest return 4 Touring 5 Touring return 6
    // X_Y1 X ... Acronym for going to work
    // Y is the departure voice (D) or the arrival voice (T)
    // Number is voice identification number
    public AudioClip S_D1;
    public AudioClip S_T1;
    public AudioClip T_D1;public AudioClip T_T1;
    private AudioSource audiosource;
    void Awake ()
    {
        RandomTime = Random.Range (180.0f, 480.0f);
        moddd = ModeSaver.mode;
        Debug.Log (moddd + "VMno");
        audiosource = gameObject.GetComponent<AudioSource>();
    }
    void Start ()
    {
    }
    void Update ()
    {
        SumTime + = Time.deltaTime;
        RestTime + = Time.deltaTime;
        RTempTime + = Time.deltaTime;
        if (lockbool == true)
        {
            if (RestTime>= 3600.0f) // Encourage a break
            {
                RestVoice ();
            }
            if (RTempTime>= RandomTime) // Boyaki
            {
                RandomVoice ();
            }
        }
    }
    public void unlock ()
    {
        lockbool = true;
    }
    public void locking ()
    {
        lockbool = false;
    }

    // Attendance 1 Retirement 2 Rest bound 3 Rest return 4 Touring 5 Touring return 6
    public void ArrivedVoice ()
    {
        switch (moddd)
        {
            case 1: // Working
                GetComponent<AudioSource>(). PlayOneShot (S_T1);
                Debug.Log ("arrivemode = 1");
                break;
            case 2: // retired
                GetComponent<AudioSource>(). PlayOneShot (T_T1);
                Debug.Log ("arrivemode = 2");
                break;
            default:
                Debug.Log ("Not in attendance mode");
                break;
        }
    }
    public void DepertureVoice (int mode)
    {
        if (mode == 1)
        {
            Debug.Log ("dmode = 1");
            GetComponent<AudioSource>(). PlayOneShot (S_D1);
        }
        else if (mode == 2) {
            GetComponent<AudioSource>(). PlayOneShot (T_D1);
            Debug.Log ("dmode = 2");
        }
        else
        {
            Debug.Log ("failure" + mode);
        }
    }
}


As a movement, VoiceManager.DepertureVoice () is called by GameManager and S_D1.wav is played
As a confirmation, dmode = 1 returns to the console. However, S_D1 is not played back as well when dmode = 2
Moreover, ArrivedVoice called after several seconds works normally.
In addition, VoiceManager.cs and all audio are attached to the VoiceManager object.
There is no error code.