Sorry for posting again but forum says I cant reply to my own Thread twice. This seems simple. I want to change the Material color that Anima2D uses in its Sprite Mesh Instance, programmically. I want the player to Slowly fade as it gets hit. I can change the color from the editor while its running but cant seem to get to the Material color, its like Anima2D locks it or something. I have tried renderer.sharedMaterial but it doesn't seem to change it. EDIT: I Figured it out, thanks. This is my flow: public EnemyShaderDamage[] allShaderDamage; // Use this for initialization void Start() { theEnemy = GetComponent<Character>(); allShaderDamage = theEnemy.GetComponentsInChildren<EnemyShaderDamage>(); } public void HurtEnemy(int damageToTake) { foreach (EnemyShaderDamage sd in allShaderDamage) { sd.HurtEnemy(damageToTake); } } below is the script that I add to each of my Body parts of the Character: using System.Collections; using System.Collections.Generic; using UnityEngine; using Anima2D; public class EnemyShaderDamage : MonoBehaviour { public SpriteMeshInstance spInstance; float m_Hue = 0f; float m_Saturation = 0.0f; float m_Value = 1.0f; public float sDecrease; public float sIncrease; // Use this for initialization void Start() { spInstance = GetComponentInChildren<SpriteMeshInstance>(); } // Update is called once per frame void Update() { } public void HurtEnemy(int damageToTake) { sDecrease = ((damageToTake * 0.65f) / 100); m_Value = (m_Value - sDecrease); spInstance.m_Color = Color.HSVToRGB(m_Hue, m_Saturation, m_Value); } public void HealEnemy(int health) { sIncrease = ((health * 0.85f) / 100); if(sIncrease > 1f) { sIncrease = 1f; } m_Value = (m_Value + sIncrease); if(m_Value > 1f) { m_Value = 1f; } spInstance.m_Color = Color.HSVToRGB(m_Hue, m_Saturation, m_Value); } public void FullHealth() { m_Value = 1f; spInstance.m_Color = Color.HSVToRGB(m_Hue, m_Saturation, m_Value); } public void Alpha(float achange) { spInstance.m_Color.a = achange; } }
solution was probably using material property block. At least I am using it all the time and never had issue with it, so it probably works for anima too. https://docs.unity3d.com/ScriptReference/MaterialPropertyBlock.html
You can acces the sprite mesh instance component using this Code (CSharp): GetComponent<Anima2D.SpriteMeshInstance>()
I edited my original post with my code: send a message if you need more info. Post was 6 months old and no one posted to it so I figured everyone already new the answer. @NoneyaBiznazz @eses