如何在Unity3d中调用随机函数

时间:2015-04-27 18:23:15

标签: ios unity3d

在iOS中我会简单地使用它;

if (arc4random() % 2 == 0) {
        //Do 1 Thing
    }else{
       // Do another
    }

使用Unity3D的方法是什么?

2 个答案:

答案 0 :(得分:1)

来自unity's documentation

if (Random.Range(minVal, maxVal) % 2 == 0) {
        //Do 1 Thing
} else {
       // Do another
}

答案 1 :(得分:1)

已放置随机值。

    var tween = new TimelineMax()
      .add(TweenMax.to("#publisher-demo-steps", 0.5, {backgroundPosition : "50% 23%"}))
      .add(TweenMax.to(".blue-circle", 1, {display: "block"}))
      .add(TweenMax.to(".blue-circle", 1, {className: "+=animated zoomOut", display: "none", delay:3}))
      .add(TweenMax.to("#publisher-demo-steps", 0.5, {backgroundPosition : "22% 52%"}))
      .add(TweenMax.to(".red-circle", 1, {display: "block"}))
      .add(TweenMax.to(".red-circle", 1, {className: "+=animated zoomOut", display: "none", delay:3}))
      .add(TweenMax.to("#publisher-demo-steps", 0.5, {backgroundPosition : "76% 50%"}))
      .add(TweenMax.to(".green-circle", 1, {display: "block"}))
      .add(TweenMax.to(".green-circle", 1, {className: "+=animated zoomOut", display: "none", delay:3}));

    var scene = new ScrollScene({triggerElement: "#publisher-demo", duration: 4000, triggerHook: -100})
              .setPin("#publisher-demo")
              .setTween(tween)
              .addTo(controller);