summaryrefslogtreecommitdiff
path: root/SurvivalTest/Assets/Scripts/Test/TestDestroySelf.cs
blob: e0457cd01b2529ac03f1c3b7a4b134608235e571 (plain)
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TestDestroySelf : MonoBehaviour
{
	public float lifeTime;

	public AnimationCurve alphaCurve;

	private float time;

	private SpriteRenderer sr;

    void Start()
    {
		Invoke("DestroySelf", lifeTime);
		time = 0;
		sr = GetComponent<SpriteRenderer>();
	}

	void DestroySelf()
	{
		this.gameObject.SetActive(false);
		Destroy(this.gameObject);
	}

	void Update()
	{
		time += Time.deltaTime;

		if (sr)
		{
			Color c = sr.color;
			c.a = alphaCurve.Evaluate(time / lifeTime);
			sr.color = c;
		}
	}

}