Okey, so I've been on this problem for ages now.
I'm trying to change a material on my character in runtime, while playing.
But everytime I change it by script, the 'starting material' that was originaly on the **GameObject**, get's **instanced** and it won't change to the new one I'm trying to put on it (see picture below).
I have to use **.materials** since it's **Element 1** I want to change, and not **Element 0**, since using **.material** only changes **Element 0**.
I've tried to use '**sharedMaterials[1]**' as well, nothing that helped.
public Material[] astronautMat;
public SkinnedMeshRenderer astronautRend;
void Start ()
{
astronautRend = GameObject.FindWithTag ("Astronaut").GetComponent();
}
void Update ()
{
AstronautMat ();
}
void AstronautMat()
{
if (Input.GetKeyDown (KeyCode.Keypad1))
{
astronautRend.materials[1] = astronautMat [0];
}
if (Input.GetKeyDown (KeyCode.Keypad2))
{
astronautRend.materials[1] = astronautMat [1];
}
}
![alt text][1]
[1]: /storage/temp/92731-renderer.jpg
↧