Hello,
I'm trying to change spine material of prefab with the script like as below:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MONSTER1_AI;
namespace Spine.Unity.Examples
{
public class SpineTint : MonoBehaviour
{
public string colorPropertyName = "_Black";
MaterialPropertyBlock mpb;
MeshRenderer monsterColorNow;
void Start()
{
mpb = new MaterialPropertyBlock();
}
void Update()
{
monsterColorNow = this.gameObject.transform.root.GetChild(0).GetComponent<MeshRenderer>();
Debug.Log(this.gameObject.transform.root.name + " " + monsterColorNow);
if(monster1_ai.whitePaint == true) // if monster took damage
{
Color newColor = Color.white; // make the material tint with white
mpb.SetColor(colorPropertyName, newColor);
monsterColorNow.SetPropertyBlock(mpb);
}
else // if monster not took damage
{
Color newColor = Color.black; // off the material tint
mpb.SetColor(colorPropertyName, newColor);
monsterColorNow.SetPropertyBlock(mpb);
}
}
}
}
And it succeed once, but it seems to affects for entire material, so color of whole monsters using same prefab is changing now.
How can I solve this? Any advices will be appreciated!!