[英]Unity C# - Spawn objects at fixed points
Instead of making objects spawn at random range on the Y-axis like this: 而不是在Y轴上使对象产生随机范围,如下所示:
float y = Random.Range(1.723573f, 5.586497f)
; float y = Random.Range(1.723573f, 5.586497f)
;
How would I make objects spawn at 2 fixed locations on the Y-axis? 如何在Y轴上的2个固定位置生成对象?
thank you 谢谢
assuming you mean you want to spawn it either at one, or the other, then try this: 假设你的意思是想要在一个或另一个上产生它,那么试试这个:
float y = Random.Range(0,100) > 50 ? 1.723573f : 5.586497f;
basically, there's a 50% chance of either the first value, or the second. 基本上,第一个值或第二个值的概率为50%。 You could alternatively type it out like this:
您也可以这样输入:
float y;
if(Random.Range(0,100) > 50)
y = 1.723573f;
else y = 5.586497f;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.