You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.1 KiB

5 years ago
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. [ExecuteInEditMode]
  5. public class ColorAnimation : MonoBehaviour {
  6. float X, Y, Z;
  7. [Range(0, 10)]
  8. public float _ColorSpeed = 6;
  9. float ColorSpeed;
  10. Vector3 RandomRangeXYZ;
  11. [SerializeField]
  12. [Range(1, 300)]
  13. float Intensity=8;
  14. void OnEnable ()
  15. {
  16. RandomRangeXYZ.x = Random.Range(0f, 1f);
  17. RandomRangeXYZ.y = Random.Range(0f, 1f);
  18. RandomRangeXYZ.z = Random.Range(0f, 1f);
  19. }
  20. // Update is called once per frame
  21. void Update () {
  22. ColorSpeed += Time.deltaTime * _ColorSpeed;
  23. X = Mathf.Sin(ColorSpeed * RandomRangeXYZ.x) * 0.5f + 0.5f;
  24. Y = Mathf.Sin(ColorSpeed * RandomRangeXYZ.y) * 0.5f + 0.5f;
  25. Z = Mathf.Sin(ColorSpeed * RandomRangeXYZ.z) * 0.5f + 0.5f;
  26. float IntensityVariable = Mathf.Sin(ColorSpeed * RandomRangeXYZ.z) * 0.5f + 0.5f;
  27. Color RandomColor = new Color(X, Y, Z, 1);
  28. GetComponent<Renderer>().sharedMaterial.SetColor("_EmissionColor", IntensityVariable*Intensity * RandomColor);
  29. }
  30. }