Change Material’s Rendering mode at runtime?

Forum Archive Change Material’s Rendering mode at runtime?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #9016
    Aunnop Kattiyanet
    Participant

      I make an rpg game and currently working on attacking system(really simple one). And I want to fade the enemy from opaque to completely transparent after it died. And I found how to change rendering mode at unity doc.

      Regarding to this link https://docs.unity3d.com/560/Documentation/Manual/MaterialsAccessingViaScript.html

      I do the same thing but it doesn’t work at all even I make a copy of the same material and put the fade version to Resources folder. I just wonder why it doesn’t work. Or I just have some problem with my interpretation…

      Here’s my code(short ver.)

      private SkinnedMeshRenderer rend;

      [chec if it’s hp <= 0]

      StartCoroutine (Fade());

      IEnumerator Fade()

      {

      yield return new WaitForSeconds(1.5f);

      rend.material.SetFloat(“_Mode”, 2);

      rend.material.EnableKeyword(“_ALPHABLEND_ON”);

      }

      [Fade color in Update() method]

      #30251
      Jonathan Gonzalez
      Participant

        It’s hard to understand your shortened version of your script. Where is the “StartCoroutine” being included? Is it in the Start method? At the end of your post you have “Fade color in Update() Method”, which seems like it would cause issues but I don’t know without seeing the completed code of this section. 

        #30252
        Aunnop Kattiyanet
        Participant
          #30253
          Aunnop Kattiyanet
          Participant

            I forgot to mention that without

            rend.material.SetInt(“_SrcBlend”, (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
            rend.material.SetInt(“_DstBlend”, (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
            rend.material.SetInt(“_ZWrite”, 0);

            in FadeColor() method, it doesn’t work at all. All these lines don’t appear in a doc, but in built-in shader code.

          Viewing 4 posts - 1 through 4 (of 4 total)
          • The topic ‘Change Material’s Rendering mode at runtime?’ is closed to new replies.