summaryrefslogtreecommitdiff
path: root/Assets/Scripts/PlayerColor.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Scripts/PlayerColor.cs')
-rw-r--r--Assets/Scripts/PlayerColor.cs35
1 files changed, 35 insertions, 0 deletions
diff --git a/Assets/Scripts/PlayerColor.cs b/Assets/Scripts/PlayerColor.cs
new file mode 100644
index 0000000..d8fedbe
--- /dev/null
+++ b/Assets/Scripts/PlayerColor.cs
@@ -0,0 +1,35 @@
+using System;
+using UnityEngine;
+
+[RequireComponent(typeof(SkinnedMeshRenderer))]
+public class PlayerColor : MonoBehaviour
+{
+ private SkinnedMeshRenderer _renderer;
+ private Material _materialInstance;
+
+ private Color _currentColor;
+ public Color color;
+
+ private void Start()
+ {
+ _renderer = GetComponent<SkinnedMeshRenderer>();
+ _materialInstance = new Material(_renderer.material);
+ _renderer.material = _materialInstance;
+ }
+
+ private void Update()
+ {
+ SetColor(color);
+ }
+
+ public void SetColor(Color newColor)
+ {
+ if (newColor == _currentColor) return;
+
+ _currentColor = newColor;
+ if (_materialInstance != null)
+ {
+ _materialInstance.SetColor("_Color", newColor);
+ }
+ }
+}