Add rainbow image scripts
This commit is contained in:
22
Assets/Scripts/RainbowImage.cs
Normal file
22
Assets/Scripts/RainbowImage.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class RainbowImage : MonoBehaviour
|
||||
{
|
||||
public float frequency = 1f;
|
||||
private Image targetImage;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
targetImage = gameObject.GetComponent<Image>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
float t = Time.time * frequency;
|
||||
float r = Mathf.Sin(t) * 0.5f + 0.5f;
|
||||
float g = Mathf.Sin(t + 2f) * 0.5f + 0.5f;
|
||||
float b = Mathf.Sin(t + 4f) * 0.5f + 0.5f;
|
||||
targetImage.color = new Color(r, g, b);
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/RainbowImage.cs.meta
Normal file
2
Assets/Scripts/RainbowImage.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ac59fc58d5aba496f8a52d26fcfe16b0
|
||||
21
Assets/Scripts/RainbowSpriteRender.cs
Normal file
21
Assets/Scripts/RainbowSpriteRender.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class RainbowSpriteRender : MonoBehaviour
|
||||
{
|
||||
public float frequency = 1f;
|
||||
private SpriteRenderer targetImage;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
targetImage = gameObject.GetComponent<SpriteRenderer>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
float t = Time.time * frequency;
|
||||
float r = Mathf.Sin(t) * 0.5f + 0.5f;
|
||||
float g = Mathf.Sin(t + 2f) * 0.5f + 0.5f;
|
||||
float b = Mathf.Sin(t + 4f) * 0.5f + 0.5f;
|
||||
targetImage.color = new Color(r, g, b);
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/RainbowSpriteRender.cs.meta
Normal file
2
Assets/Scripts/RainbowSpriteRender.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a21a35a47faba4555ab8f7fa25ebe2a0
|
||||
Reference in New Issue
Block a user