您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
34 行
845 B
34 行
845 B
using UnityEngine;
|
|
|
|
namespace BoatAttack
|
|
{
|
|
/// <summary>
|
|
/// Simple scripts sets a random HUE on a shader with the property '_Hue'
|
|
/// </summary>
|
|
public class RandomHue : MonoBehaviour
|
|
{
|
|
public MeshRenderer[] renderers;
|
|
private static readonly int Hue = Shader.PropertyToID("_Hue");
|
|
|
|
private void OnEnable()
|
|
{
|
|
RandomizeHue();
|
|
}
|
|
|
|
void RandomizeHue()
|
|
{
|
|
var hue = Random.Range(0f, 1f);
|
|
|
|
if (renderers == null || renderers.Length <= 0) return;
|
|
|
|
foreach (var t in renderers)
|
|
{
|
|
if (t == null) continue;
|
|
|
|
var mat = new Material(t.sharedMaterial);
|
|
mat.SetFloat(Hue, hue);
|
|
t.material = mat;
|
|
}
|
|
}
|
|
}
|
|
}
|