-
Notifications
You must be signed in to change notification settings - Fork 171
Expand file tree
/
Copy pathShell.cs
More file actions
37 lines (28 loc) · 819 Bytes
/
Shell.cs
File metadata and controls
37 lines (28 loc) · 819 Bytes
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
using UnityEngine;
using System.Collections;
public class Shell : MonoBehaviour {
public Rigidbody myRigidbody;
public float forceMin;
public float forceMax;
float lifetime = 4;
float fadetime = 2;
void Start () {
float force = Random.Range (forceMin, forceMax);
myRigidbody.AddForce (transform.right * force);
myRigidbody.AddTorque (Random.insideUnitSphere * force);
StartCoroutine (Fade ());
}
IEnumerator Fade() {
yield return new WaitForSeconds(lifetime);
float percent = 0;
float fadeSpeed = 1 / fadetime;
Material mat = GetComponent<Renderer> ().material;
Color initialColour = mat.color;
while (percent < 1) {
percent += Time.deltaTime * fadeSpeed;
mat.color = Color.Lerp(initialColour, Color.clear, percent);
yield return null;
}
Destroy (gameObject);
}
}