blob: 1ccd82561e1d6e3b7179b4add4a0b63cb71050ed (
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
|
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;
Color c = sr.color;
c.a = alphaCurve.Evaluate(time / lifeTime);
sr.color = c;
}
}
|