Hi everyone, I have a model I’ve imported from blender. it is automatically imported with the “Skinned Mesh Renderer” component. in a tutorial I am going through, I need to change the color of one of that model through code. the problem is, I get this error, and the color remains the same
Material doesn't have a color property '_Color'
UnityEngine.Material:GetColor(String)
Chest:Start() (at Assets/Scripts/Chest.cs:26)
In the tutorial he tutor is using the exact same script, but it works for him, basically it just needs to tint the model yellow.
here is my code:
using UnityEngine;
using System.Collections;
public class Chest : MonoBehaviour {
public enum State {
open,
close,
inbetween
}
public AudioClip openSound;
public AudioClip closeSound;
public GameObject[] parts;
private Color[] _defaultColors;
public State _state;
// Use this for initialization
void Start () {
_state = Chest.State.close;
_defaultColors = new Color[parts.Length];
if (parts.Length > 0){
for(int cnt = 0; cnt < _defaultColors.Length; cnt++){
_defaultColors[cnt] = parts[cnt].renderer.material.GetColor("_Color");
}
}
}
public void OnMouseEnter() {
Debug.Log("enter");
HighLight(true);
}
public void OnMouseExit() {
Debug.Log("exit");
HighLight(false);
}
public void OnMouseUp() {
Debug.Log("Up");
switch(_state){
case State.open:
_state = Chest.State.inbetween;
StartCoroutine("Close");
break;
case State.close:
_state = Chest.State.inbetween;
StartCoroutine("Open");
break;
}
// if (_state == Chest.State.close){
// Open ();
// }
// else{
// Close();
// }
}
private IEnumerator Open(){
animation.Play("Open");
audio.PlayOneShot(openSound);
yield return new WaitForSeconds(animation["Open"].length);
_state = Chest.State.open;
}
private IEnumerator Close(){
animation.Play("Close");
audio.PlayOneShot(closeSound);
yield return new WaitForSeconds(animation["Close"].length);
_state = Chest.State.close;
}
private void HighLight(bool glow){
if(glow) {
if (parts.Length > 0){
for(int cnt = 0; cnt < _defaultColors.Length; cnt++){
parts[cnt].renderer.material.SetColor("_Color", Color.yellow);
}
}
}
else {
if (parts.Length > 0){
for(int cnt = 0; cnt < _defaultColors.Length; cnt++){
parts[cnt].renderer.material.SetColor("_Color", _defaultColors[cnt]);
}
}
}
}
}
Here is how wit appears in the editor;
[7386-color+problems.jpg|7386]
I realise that there is no color poperty in it’s mesh renderer, but the person who hosted the tutorial had it, and I’m not sure why I don’t. I’m using unity 4.x and I created my models in blender.