停止rnd = Math.floor(Math.random()* 3)+ 1;

时间:2017-04-15 04:35:54

标签: actionscript-3

我希望能够从

获得不同的号码
rnd = Math.floor(Math.random() * 3) + 1;

但它每次都会给我一个数字,导致不同的陈述成真。

if (rnd == 1) {
        chest1.gotoAndStop("chest");
    }
    if (rnd == 2) {
        chest2.gotoAndStop("chest");
    }
    if (rnd == 3) {
        chest3.gotoAndStop("chest");
    }

我想要它所以它做了一次,然后在我成功返回胸部导致另一个胸部出现后再给我另一个号码。但它不是,只是让同样的胸部出现:(

1 个答案:

答案 0 :(得分:1)

这是否有效:

switch (Math.floor(Math.random() * 3) + 1)
{
case 1:
    chest1.gotoAndStop("chest");
    break;
case 2:
    chest2.gotoAndStop("chest");
    break;
case 3:
    chest3.gotoAndStop("chest");
    break;
}