为什么音频在我的代码统一中不起作用?统一c#
出于某种原因,我的代码是音频不工作的唯一。。。我不知道为什么。有人能帮忙吗?我正在使用为什么音频在我的代码统一中不起作用?统一c#,c#,unity3d,C#,Unity3d,出于某种原因,我的代码是音频不工作的唯一。。。我不知道为什么。有人能帮忙吗?我正在使用音频剪辑[]我的代码: using System.Collections; using System.Collections.Generic; using UnityEngine; public class LevelManage : MonoBehaviour { public GameObject[] animals; public GameObject[] blackAnimals;
音频剪辑[]
我的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LevelManage : MonoBehaviour
{
public GameObject[] animals;
public GameObject[] blackAnimals;
Vector3[] animalStartPos;
Vector3[] animalBlackStartPos;
public AudioSource source;
public AudioClip[] Correct;
public AudioClip InCorrect;
void Start()
{
animalStartPos = new Vector3[animals.Length];
animalBlackStartPos = new Vector3[blackAnimals.Length];
for (int i = 0; i < animals.Length; i++)
{
animalStartPos[i] = animals[i].transform.position;
animalBlackStartPos[i] = blackAnimals[i].transform.position;
}
}
//drag
public void dragAnimal(GameObject animal)
{
animal.transform.position = Input.mousePosition;
}
//drop
public void dropAnimal(GameObject animal)
{
int index = System.Array.IndexOf(animals, animal);
float dist = Vector3.Distance(animal.transform.position, blackAnimals[index].transform.position);
if (dist < 75)
{
animal.transform.position = blackAnimals[index].transform.position;
source.clip = Correct[Random.Range(0, Correct.Length)];
source.Play();
}
else
{
animal.transform.position = animalStartPos[index];
source.clip = InCorrect;
source.Play();
}
}
}
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
公共类级别管理:单一行为
{
公共游戏对象[]动物;
公共游戏对象[]黑色动物;
向量3[]动物起点;
Vector3[]动物黑星;
公共音频源;
公共音频剪辑[]正确;
公共音频剪辑不正确;
void Start()
{
animalStartPos=新向量3[动物.长度];
animalBlackStartPos=新向量3[blackAnimals.Length];
for(int i=0;i
控制台有错误:
UnassignedReferenceException:尚未分配LevelManage的变量源
您可能需要在inspector中指定LevelManage脚本的源变量
请帮忙
非常感谢您的回答。1)通过在“项目”面板中选择剪辑并进行类似的播放,确保您的剪辑被正确导入并在unity编辑器中实际播放
2) 确保您的源卷不是0
3) 确保您的源代码.mute
为false
4) 确保您的AudioListener.volume
(全局卷)不是0
5) 确保您的AudioListener.pause
(全局暂停)为false
6) 确保编辑器中的“静音音频”切换未切换这是您可以找到它的地方检查器中音频源的设置是否正确?inspector中的volume选项可能设置为非常低。听起来您只是没有引用inspector中的一个字段。。基本上,这正是错误所暗示的。请发布LevelManage
组件检查器设置的屏幕截图。您得到的错误只是NullReferenceException
的一种特殊形式。谢谢@derHugo我忘了将它添加到LevelManager谢谢--现在我遇到了这个错误//UnassignedReferenceException:LevelManager的变量源尚未分配。您可能需要在inspector中指定LevelManage脚本的源变量。