简体   繁体   English

使用未分配的局部变量“随机”

[英]Use of unassigned local variable 'Random'

I made an spawner in Unity but I got some errors:我在 Unity 中制作了一个生成器,但出现了一些错误:

error CS0165: Use of unassigned local variable 'Random'错误 CS0165:使用未分配的局部变量“随机”

error CS1061: 'float' does not contain a definition for 'Range' and no accessible extension method 'Range' accepting a first argument of type 'float' could be found错误 CS1061:“float”不包含“Range”的定义,并且找不到接受“float”类型的第一个参数的可访问扩展方法“Range”

all these error's says that this line of code:所有这些错误都表明这行代码:

float Random = Random.Range(0,100) / 100;

doesn't work.不起作用。

Why these errors appeard?为什么会出现这些错误? How to repair it?如何修复它?

I can't comment so I will post my assumption here我不能发表评论,所以我会在这里发表我的假设

You named float Random witch is a class你命名的 float Random 女巫是 class

Try naming it rnd like this:尝试将其命名为 rnd,如下所示:

 float rnd = Random.Range(0f, 1f);

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

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