Newer
Older
John Schihada
committed
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
60
61
62
63
64
//
// Rain Maker (c) 2016 Digital Ruby, LLC
// http://www.digitalruby.com
//
using UnityEngine;
using System.Collections.Generic;
namespace DigitalRuby.RainMaker
{
public class RainCollision : MonoBehaviour
{
private static readonly Color32 color = new Color32(255, 255, 255, 255);
private readonly List<ParticleCollisionEvent> collisionEvents = new List<ParticleCollisionEvent>();
public ParticleSystem RainExplosion;
public ParticleSystem RainParticleSystem;
private void Start()
{
}
private void Update()
{
}
private void Emit(ParticleSystem p, ref Vector3 pos)
{
int count = UnityEngine.Random.Range(2, 5);
while (count != 0)
{
float yVelocity = UnityEngine.Random.Range(1.0f, 3.0f);
float zVelocity = UnityEngine.Random.Range(-2.0f, 2.0f);
float xVelocity = UnityEngine.Random.Range(-2.0f, 2.0f);
const float lifetime = 0.75f;// UnityEngine.Random.Range(0.25f, 0.75f);
float size = UnityEngine.Random.Range(0.05f, 0.1f);
ParticleSystem.EmitParams param = new ParticleSystem.EmitParams();
param.position = pos;
param.velocity = new Vector3(xVelocity, yVelocity, zVelocity);
param.startLifetime = lifetime;
param.startSize = size;
param.startColor = color;
p.Emit(param, 1);
count--;
}
}
private void OnParticleCollision(GameObject obj)
{
if (RainExplosion != null && RainParticleSystem != null)
{
int count = RainParticleSystem.GetCollisionEvents(obj, collisionEvents);
for (int i = 0; i < count; i++)
{
ParticleCollisionEvent evt = collisionEvents[i];
Vector3 pos = evt.intersection;
Emit(RainExplosion, ref pos);
}
}
}
}
}