[英]Random array string assigned to a text component - Unity 4.6, uGUI
Need some help with this one. 需要一些帮助。 I'm creating an array with a list of descriptions (strings) that I need to choose randomly and then assign to a text component in a gameobject. 我正在创建一个包含需要随机选择的描述(字符串)列表的数组,然后将其分配给游戏对象中的文本组件。
I feel like I'm close but I'm getting an error: 我觉得我已经接近了,但出现错误:
Type `UnityEngine.Random' does not contain a definition for `Next' and no extension method `Next' of type `UnityEngine.Random' could be found (are you missing a using directive or an assembly reference?) 类型“ UnityEngine.Random”不包含“下一个”的定义,找不到类型为“ UnityEngine.Random”的扩展方法“下一个”(您是否缺少using指令或程序集引用?)
What should I be using instead of 'Next'? 我应该使用什么代替“下一步”?
public Text myText;
Random rand = new Random();
public string[] animalDescriptions =
{
"Description 1",
"Description 2",
"Description 3",
"Description 4",
"Description 5",
};
void Start()
{
string myString = animalDescriptions[rand.Next(animalDescriptions.Length)];
myText.text = myString;
Debug.Log (myString);
}
Looks like when you don't use it's full name, your Random
will be referring to UnityEngine.Random
not System.Random
class (because you have already used this in your namespace etc..). 看起来,当您不使用它的全名时,您的Random
将会引用UnityEngine.Random
而不是System.Random
类(因为您已经在名称空间中使用了它,等等。)。
Use it's full name as; 将其全名用作;
System.Random rand = new System.Random();
or change your UnityEngine.Random
name to something else (which I suggest). 或将您的UnityEngine.Random
名称更改为其他名称(建议这样做)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.