简体   繁体   English

统一音频 null

[英]Audio null in unity

I am getting this weird error in unity when I am trying to run my (sad excuse for a) game.当我尝试运行我的(悲伤的借口)游戏时,我遇到了这个奇怪的统一错误。 Here's the code这是代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ARsound : MonoBehaviour
{

    public static AudioClip sound;
    static AudioSource audioSrc;


    void Start()
    {
        sound = Resources.Load<AudioClip>("AR SFX");
        audioSrc = GetComponent<AudioSource>();
    }

    public static void playSound()
    {
        audioSrc.PlayOneShot(sound);
    }


}

And the error is this:错误是这样的:

PlayOneShot was played with a null audio clip PlayOneShot 使用 null 音频剪辑播放

Even though that audio clip doesn't SEEM to be null.即使该音频剪辑似乎不是 null。 Here is some additional info:这是一些附加信息:

Gun:Update() (at Assets/Scripts/Gun.cs:17) Gun:Update() (在 Assets/Scripts/Gun.cs:17)

Suggestions?建议?

Your call to Resources.Load returns null - this happens when the asset is not found (no exception).您对Resources.Load的调用返回 null - 当找不到资产时会发生这种情况(无例外)。

See docs: https://docs.unity3d.com/ScriptReference/Resources.Load.html请参阅文档: https://docs.unity3d.com/ScriptReference/Resources.Load.html

So you need to make sure that the asset exists and that it can be loaded.因此,您需要确保资产存在并且可以加载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM