-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCell.cs
More file actions
69 lines (42 loc) · 1.28 KB
/
Cell.cs
File metadata and controls
69 lines (42 loc) · 1.28 KB
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
65
66
67
68
69
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Cell : MonoBehaviour
{
public bool alive;
//colour
public Color DefaultColour = Color.green;
public Color HighligtColour = Color.red;
public int Lerpspeed = 1;
public SpriteRenderer spriteRenderer;
public Material _mat;
public void Start()
{
spriteRenderer = GetComponent<SpriteRenderer>();
_mat = spriteRenderer.material;
DefaultColour = _mat.GetColor("_Color");
StartCoroutine(UpdateColour());
}
public void UpdateStatus()
{
if (spriteRenderer == null)
{
spriteRenderer = GetComponent<SpriteRenderer>();
}
spriteRenderer.enabled = alive;
}
public void OnEnable()
{
StartCoroutine(UpdateColour());
}
public IEnumerator UpdateColour()
{
while (true)
{
float lerpvalue = Mathf.PingPong(Lerpspeed * Time.time, 1);
Color LerpColor = Color.Lerp(DefaultColour,HighligtColour,lerpvalue);
_mat.SetColor("_Color", LerpColor);
yield return new WaitForEndOfFrame();
}
}
}