Search Unity

Dissolve Shader

Discussion in 'Scripting' started by TheDevGuy, Sep 21, 2014.

  1. TheDevGuy

    TheDevGuy

    Joined:
    Mar 3, 2014
    Posts:
    78
    I am currently trying to conrol the dissolve speed on the shader through an activated script on the same object, but i cannot seem to alter the code so that it does not loop:

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Timed : MonoBehaviour
    5. {
    6.   public float m_fDestruktionSpeed = 0.1f;
    7.   public Material m_Mat;
    8.   public float m_fTime;
    9.  
    10.    void Start () {
    11.   m_Mat = renderer.material;
    12.    }
    13.  
    14.    void Update () {
    15.   m_fTime += Time.deltaTime * m_fDestruktionSpeed;
    16.   if (m_fTime >= 1.5f)
    17.   m_fTime = 0;
    18.   m_Mat.SetFloat("_Amount", m_fTime);
    19.    }
    20. }
    How can i alter this to make it just dissolve one time when i activate the component.

    Thank you
     
  2. raycosantana

    raycosantana

    Joined:
    Dec 23, 2012
    Posts:
    319
    Why don't you just use a bool variable?
    You set a conditional for this bool to be true, when you are done you just set it to false and it wont run anymore.
     
  3. TheDevGuy

    TheDevGuy

    Joined:
    Mar 3, 2014
    Posts:
    78
    Yea I just bought this, and that script came with it.

    Unfortunately I don't code. I use Playmaker.

    So how would a simple script that affects the _Amount on the shader over time look?

    Thank you for your help.
     
  4. BmxGrilled

    BmxGrilled

    Joined:
    Jan 27, 2014
    Posts:
    239
    change line 16 from
    if (m_fTime >= 1.5f)
    to
    if (m_fTime < 1.5f)
    and remove line 17

    Should do the trick, hope this helps! :)
     
  5. TheDevGuy

    TheDevGuy

    Joined:
    Mar 3, 2014
    Posts:
    78
    Yes that works thank you
     
  6. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    SuperEmma to the rescue <cue theme music> saving the day, one script at a time.