Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class MaterialPropertyBlockTest : MonoBehaviour {
- public bool lerp;
- public float amplitude = 3f;
- [Header("Color Primary")]
- [Range(0, 1)]
- public float HueMin1 ;
- [Range(0, 1)]
- public float HueMax1 =1f;
- [Range(0, 1)]
- public float SaturationMin1;
- [Range(0, 1)]
- public float SaturationMax1=1f;
- [Range(0, 1)]
- public float ValueMin1;
- [Range(0, 1)]
- public float ValueMax1=1f;
- [Header("Color Secondary")]
- [Range(0, 1)]
- public float HueMin2;
- [Range(0, 1)]
- public float HueMax2=1f;
- [Range(0, 1)]
- public float SaturationMin2;
- [Range(0, 1)]
- public float SaturationMax2=1f;
- [Range(0, 1)]
- public float ValueMin2;
- [Range(0, 1)]
- public float ValueMax2=1f;
- [Header("Color Tertiary")]
- [Range(0, 1)]
- public float HueMin3;
- [Range(0, 1)]
- public float HueMax3=1f;
- [Range(0, 1)]
- public float SaturationMin3;
- [Range(0, 1)]
- public float SaturationMax3=1f;
- [Range(0, 1)]
- public float ValueMin3;
- [Range(0, 1)]
- public float ValueMax3=1f;
- Color randomColor;
- Color randomColor2;
- Color randomColor3;
- MeshRenderer renderer;
- MaterialPropertyBlock props;
- // Use this for initialization
- void Start () {
- props = new MaterialPropertyBlock();
- randomColor = Random.ColorHSV(HueMin1, HueMax1, SaturationMin1, SaturationMax1, ValueMin1, ValueMax1);
- randomColor2 = Random.ColorHSV(HueMin2, HueMax2, SaturationMin2, SaturationMax2, ValueMin2, ValueMax2);
- randomColor3 = Random.ColorHSV(HueMin3, HueMax3, SaturationMin3, SaturationMax3, ValueMin3, ValueMax3);
- props.SetColor("_Color", randomColor);
- props.SetColor("_ColorSec", randomColor2);
- props.SetColor("_ColorTert", randomColor3);
- renderer = GetComponent<MeshRenderer>();
- renderer.SetPropertyBlock(props);
- }
- // Update is called once per frame
- void Update () {
- if (lerp)
- {
- props.SetColor("_Color", Color.Lerp(Color.cyan, Color.magenta, (Mathf.Sin(Time.time * amplitude + (transform.position.x + transform.position.z)) + 1) / 2f));
- renderer.SetPropertyBlock(props);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment