SHARE
TWEET

ChangeColor

opponent019 May 2nd, 2018 (edited) 1 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. // Script that goes with WavySphere shader: https://pastebin.com/AZiuUYwp
  6. // Made by Erika Moya
  7.  
  8. public class ChangeColor : MonoBehaviour {
  9.  
  10.     public Gradient colorGradient;
  11.     public float strobeDuration = 2f;
  12.     SkinnedMeshRenderer rend;
  13.  
  14.     public float startPoint = 5f;
  15.     public int seconds = 5;
  16.     public float speed = 1.00f;
  17.     public float blend = 0;
  18.  
  19.     public Light light;
  20.  
  21.     public float t;
  22.  
  23.     float startTime;
  24.     public bool loop = true;
  25.  
  26.     private void Start()
  27.     {
  28.         rend = GetComponent<SkinnedMeshRenderer>();
  29.         startTime = Time.time;
  30.         t = startPoint;
  31.         rend.material.SetFloat("_Blend", 0);
  32.         rend.SetBlendShapeWeight(1, 0);
  33.  
  34.         RenderSettings.ambientLight = Color.grey;
  35.     }
  36.  
  37.     // Update is called once per frame
  38.     void Update ()
  39.     {
  40.         float p = Mathf.PingPong(Time.time / strobeDuration, 1f);
  41.         rend.material.SetColor("_Color", colorGradient.Evaluate(p));
  42.  
  43.         t -= Time.deltaTime;
  44.        
  45.         if (t < 0 || !loop)
  46.         {
  47.  
  48.             p = (Time.time - startPoint) * speed;
  49.             //blend = Mathf.Lerp(0, 1, t / seconds);
  50.             blend = Mathf.PingPong(p / seconds, 1f);
  51.  
  52.             if (blend >= 0.97)
  53.             {
  54.                 t = startPoint;
  55.                 blend = 1;
  56.             }
  57.             if (blend <= 0.03)
  58.             {
  59.                 t = startPoint;
  60.                 blend = 0;
  61.             }
  62.  
  63.             rend.material.SetFloat("_Blend", blend);
  64.             rend.SetBlendShapeWeight(1, blend * 100);
  65.             RenderSettings.ambientLight = Color.Lerp(Color.grey, Color.white, blend);
  66.             light.intensity = Mathf.Lerp(.35f, 0, blend);
  67.            
  68.         }
  69.     }
  70.    
  71. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top