now I'm doing the multi choice from lists but the voice didn't come out. what should i do?
Cannot implicitly convert type void' to
UnityEngine.AudioSource'
using UnityEngine; using System.Collections; using UnityEngine.UI; using System.Collections.Generic;
public class test : MonoBehaviour {
string[,] data = new string[3,3];
string[] WrongAnswer;
public Text Answer1;
public Text Answer2;
public AudioClip clip;
public AudioSource Sound_Question;
public AudioSource Sound;
public int question = 0;
List<Choice> list = new List<Choice>();
// Use this for initialization
void Start () {
init();
showQuestion();
Sound = GetComponent<AudioSource> ();
}
public void showQuestion()
{
Sound_Question = list[question].Question;
int rand = Random.Range(1, 3);
if(rand == 1)
{
Answer1.text = list[question].CorrectAnswer;
Answer2.text = list[question].WrongAnswer[Random.Range(0, list[question].WrongAnswer.Length)];
Answer1.GetComponent<Property>().isCorrect = true;
Answer2.GetComponent<Property>().isCorrect = false;
}
else
{
Answer2.text = list[question].CorrectAnswer;
Answer1.text = list[question].WrongAnswer[Random.Range(0, list[question].WrongAnswer.Length)];
Answer2.GetComponent<Property>().isCorrect = true;
Answer1.GetComponent<Property>().isCorrect = false;
}
}
public void init()
{
list.Add(new Choice()
{
Question = Sound.GetComponent<AudioSource>(),
CorrectAnswer="ANT",
WrongAnswer = new string[] { "CAT","RAT","IN"}
});
list.Add(new Choice()
{
Question = Sound2.GetComponent<AudioSource>(),
CorrectAnswer = "SNAKE",
WrongAnswer = new string[] { "IN", "TOP", "SPIN" }
});
}
void Question()
{
int pos = Random.Range(1, 3);
if (pos == 1)
{
Answer1.text = data[pos, question];
Answer2.text = data[pos + 1, question];
}
else if (pos == 2)
{
Answer1.text = data[pos, question];
Answer2.text = data[pos - 1, question];
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612065104im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
I want to change the reference axis of an object relative to the camera of another object 0 Answers
I need a little help with headbobber script (C#) 0 Answers
Can i make my camera rotate towards the object or any point for VR? 0 Answers
Required Human Bone "Head" not found 4 Answers
About making a character with "head" swapable ,Making a character with a "changeable" head 0 Answers