-
Notifications
You must be signed in to change notification settings - Fork 3
/
SnowflakeSystem.js
59 lines (47 loc) · 1.27 KB
/
SnowflakeSystem.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#pragma strict
var flakePrefab : GameObject;
var bounds : Bounds2D;
var numFlakes = 10;
var baseVelocity = Vector3( 0, -0.1, 0 );
var stdevVelocity = Vector3( 0.2, 0, 0 );
class Flake
{
var obj:GameObject;
var velocity:Vector3;
var resetTime:float;
function Flake( _obj:GameObject, _vel:Vector3 )
{
obj = _obj;
velocity = _vel;
}
}
private var flakes : Flake[];
function ResetFlake( flake:Flake ) : void
{
flake.obj.transform.localPosition = bounds.RandomPosition();
flake.resetTime = Time.time + Random.Range( 10.0, 20.0 );
flake.velocity = baseVelocity + stdevVelocity*Utils.PseudoNormalRandom(0, 1.0);
}
function Start () {
flakes = new Flake[ numFlakes ];
for( var i = 0; i < numFlakes; i++ ) {
var obj = Instantiate( flakePrefab );
obj.transform.parent = transform;
flakes[i] = new Flake( obj, Vector3(0,0,0) );
ResetFlake( flakes[i] );
}
// hide prefab
flakePrefab.GetComponent.<Renderer>().enabled = false;
}
function Update () {
// time-step all flakes..
for( var i = 0; i < numFlakes; i++ ) {
var xform = flakes[i].obj.transform;
xform.localPosition = bounds.WrapPosition(
xform.localPosition + flakes[i].velocity*Time.deltaTime );
//if( flakes[i].resetTime < Time.time ) {
// reset the flake
//ResetFlake( flakes[i] );
//}
}
}