-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFadeToBlueScript.cs
64 lines (47 loc) · 1.4 KB
/
FadeToBlueScript.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
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FadeToBlueScript : MonoBehaviour {
// Reference to game objects Sprite Renderer component
SpriteRenderer rend;
// Variable to hold value to fade down to.
// Can be adjusted in inspector with slider
[Range(0f, 1f)]
public float fadeToBlueAmount = 0f;
// Variable to hold fading speed
public float fadingSpeed = 0.05f;
// Use this for initialization
void Start () {
// Getting Sprite Renderer component
rend = GetComponent<SpriteRenderer> ();
// Getting access to Color options
Color c = rend.material.color;
// Setting initial values for Red and Green channels
c.r = 1f;
c.g = 1f;
// Set sprite colors
rend.material.color = c;
}
// Coroutine to slowly fade down to desireable color
IEnumerator FadeToBlue()
{
// Loop that runs from 1 down to desirable Blue Channel Color amount
for (float i = 1f; i >= fadeToBlueAmount; i -= 0.05f)
{
// Getting access to Color options
Color c = rend.material.color;
// Setting values for Red and Green channels
c.r = i;
c.g = i;
// Set color to Sprite Renderer
rend.material.color = c;
// Pause to make color be changed slowly
yield return new WaitForSeconds (fadingSpeed);
}
}
// Method that starts fading coroutine when UI button is pressed
public void StartFadeToBlue()
{
StartCoroutine ("FadeToBlue");
}
}