Files
CartoonRPG/Assets/StixGames/GrassShader/Scripts/GrassRegenerator.cs
Caleb Sandford deQuincey 02c4b5ab66 Adding in new packages
2025-06-05 22:59:18 +01:00

42 lines
994 B
C#

using UnityEngine;
namespace StixGames.GrassShader
{
[AddComponentMenu("Stix Games/Deprecated/Grass Regenerator")]
public class GrassRegenerator : MonoBehaviour
{
public float regenerationSpeed = 1;
private Texture2D texture;
private readonly Color originalColor = new Color(0.5f, 0.5f,1,1);
void Update ()
{
if (texture == null)
{
texture = GrassManipulationUtility.GetGrassTexture(transform, false);
}
Color[] pixels = texture.GetPixels();
for (int i = 0; i < pixels.Length; i++)
{
pixels[i] = Color.Lerp(pixels[i], originalColor, regenerationSpeed * Time.deltaTime);
}
texture.SetPixels(pixels);
//Search for texture updater, which prevents multiply applys per frame (for multiple displacers)
TextureUpdater updater = GetComponent<TextureUpdater>();
if (updater == null)
{
updater = gameObject.AddComponent<TextureUpdater>();
updater.targetTexture = texture;
}
updater.RequestTextureUpdate();
}
}
}