Skip to content

Instantly share code, notes, and snippets.

@geta6
Created October 21, 2011 09:20

Revisions

  1. geta6 created this gist Oct 21, 2011.
    24 changes: 24 additions & 0 deletions BoxGenerate.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    var interval : float;
    var redBoxPrefav : GameObject;
    var blueBoxPrefav : GameObject;

    private var isRed : boolean;
    private var nextTime : float;

    function Start () {
    isRed = true;
    nextTime = 0.0;
    }

    function Update () {
    nextTime -= Time.deltaTime;
    if (nextTime < 0.0) {
    var offsetX : float = Random.Range(-18.0, 18.0);
    var offsetZ : float = Random.Range(-12.0, 12.0);
    var position : Vector3 = transform.position + Vector3(offsetX, 0, offsetZ);
    var prefab : GameObject = isRed?redBoxPrefav:blueBoxPrefav;
    Instantiate(prefab, position, Random.rotation);
    nextTime = interval;
    isRed = !isRed;
    }
    }