title: Change multiple materials in one GameObject in Unity3D
body: <p>I'll make this short. I have a gameobject and it has a sprite renderer and a particle renderer. What I want to do is, when I give it a command from the script, i want the sprite renderer of the  gameobject to change the material, however if I do it like this :
      using UnityEngine;
      using System.Collections;</p>
  
  <pre><code>public class DoorBehav : MonoBehaviour {
  
  public static float DoorHp = 100f;
  
  public TextMesh HpText;
  public Material brokenMat; //the material I want to use for the sprite renderer
  
  private GameObject hero;
  ParticleEmitter partEmit;
  
  void Start () {
      hero = GameObject.Find("Hero");
      partEmit = GetComponent&lt;ParticleEmitter&gt; ();
      HpText = transform.FindChild ("DoorHp").GetComponent&lt;TextMesh&gt;() as TextMesh;
      HpText.color = Color.green;
  }
  
  void Update () {
      if (Vector3.Distance (hero.transform.position, transform.position) &lt; 1.8f)
         {
          HeroBehaviour.agent.speed = 0;
          DoorHp-=1f;
          partEmit.Emit();
          HpText.text = ((Mathf.FloorToInt(DoorHp)).ToString()+"%");
  
          if(DoorHp &lt;=60f)
          {
              transform.renderer.material = brokenMat;
              HpText.color = Color.yellow;
          }
          if(DoorHp &lt;=30f)
          {
              HpText.color = Color.red;
          }
          if(DoorHp &lt;=0)
          {
              //play sound : destroy door
              HeroBehaviour.agent.speed = HeroBehaviour.moveSpeed; 
              Destroy(this.gameObject);
          }
      }
  }
  ...
  </code></pre>
  
  <p>Basically, this is a door and when the hero gets close to it, it loses hp (hitpoints). If the hp variable is lower than 60, it changes the look of the door to a broken door. However, when I do this, it also changes the material of the particle renderer and it starts spilling out tiny little broken doors instead of the derbis of the broken door. How do I get it to ONLY change the material of the sprite renderer? I've tried countless times but I can't get it to work :(  By the way, I can not add any children to this gameobject, it would mess up many things. Thanks in advance! :)</p>