拥有通常无效的令牌“=”我通常可以修复。这次我无法绕过什么错误。我是一个新的,年轻的程序员,正在学习,所以这可能是非常明显的,但如果你能回复感谢真的会有所帮助!
这是错误的代码
audio = (AudioSource)AudioClip.AddComponent ("AudioSource");
AudioClip myAudioClip;
myAudioClip = (AudioClip)Resources.Load("SFX/DoNotQuestionTheAdventureVoice");
audio.clip = myAudioClip;
如果您需要,这是完整的代码:
using UnityEngine;
using System.Collections;
public class Button : MonoBehaviour {
public AudioSource audio;
public AudioClip buttonSound;
void Update(){}
void start ();
audio = (AudioSource)AudioClip.AddComponent ("AudioSource");
AudioClip myAudioClip;
myAudioClip = (AudioClip)Resources.Load("SFX/DoNotQuestionTheAdventureVoice");
audio.clip = myAudioClip;
void OnGUI () {
if (GUI.Button (new Rect (300, 300, 400, 50), "Do not question the adventure voice!")) {
audio.Play ();
}
}
}
答案 0 :(得分:1)
也许你的代码格式不正确,但基于此,你的代码在你的类声明中,但看起来应该在start
方法中。
重新格式化并修复了以下代码。
using UnityEngine;
using System.Collections;
public class Button : MonoBehaviour
{
public AudioSource audio;
public AudioClip buttonSound;
void Update()
{
}
// Changed from start(); which is not valid
// Also, this may need to be "Start" (note the difference in casing)
void start()
{
audio = (AudioSource)AudioClip.AddComponent ("AudioSource");
AudioClip myAudioClip;
myAudioClip = (AudioClip)Resources.Load("SFX/DoNotQuestionTheAdventureVoice");
audio.clip = myAudioClip;
}
void OnGUI ()
{
if (GUI.Button (new Rect (300, 300, 400, 50), "Do not question the adventure voice!")) {
audio.Play ();
}
}