-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFadeDead.cs
39 lines (34 loc) · 1014 Bytes
/
FadeDead.cs
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FadeDead : MonoBehaviour
{
public int fadeSpeed = 3;
private bool isDone = false;
private Color matCol;
private Color newColor;
private float alfa = 0;
// Use this for initialization
void Start ()
{
Renderer renderer = gameObject.GetComponent<Renderer> ();
matCol = renderer.material.color;
}
// Update is called once per frame
void Update ()
{
Renderer renderer = gameObject.GetComponent<Renderer> ();
if (!isDone) {
alfa = renderer.material.color.a - Time.deltaTime / (fadeSpeed == 0 ? 1 : fadeSpeed);
if (gameObject.GetComponent<Rigidbody2D>() && alfa < 0.7) {
gameObject.GetComponent<Collider2D>().enabled = false;
Destroy(gameObject.GetComponent<Rigidbody2D>());
}
newColor = new Color (matCol.r, matCol.g, matCol.b, alfa);
renderer.material.SetColor ("_Color", newColor);
isDone = alfa <= 0 ? true : false;
} else {
gameObject.SetActive (false);
}
}
}