Advertisement
DaDogeDevelopment

Rainbow

Jul 4th, 2023
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.63 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class Rainbow : MonoBehaviour
  4. {
  5.     public float speed = 1.0f; // The speed at which the color changes
  6.     private Renderer renderer;
  7.     private float hue = 0.0f; // The current hue value
  8.  
  9.     private void Start()
  10.     {
  11.         renderer = GetComponent<Renderer>();
  12.     }
  13.  
  14.     private void Update()
  15.     {
  16.         hue = (hue + Time.deltaTime * speed) % 1.0f; // Increase the hue value and wrap it around at 1.0
  17.         Color color = Color.HSVToRGB(hue, 1, 1); // Convert the hue value to an RGB color
  18.         renderer.material.color = color; // Set the material color to the rainbow color
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement