Author Topic: Unity3d Animate Substance Texture.  (Read 3821 times)

I have used the following script to animate a substance slider in unity3d.  The script causes the glow effect (lights) to turn on and off in a pattern.  I built a portal system when they step in the portal it causes the lights to animate up to top and restarts at the bottom.  The problem is when you step out and back into the portal it doesn’t reset the lights back to the start.  Instead it starts up where it left off at.

Code: [Select]
using UnityEngine;
using System.Collections;

public class Lights : MonoBehaviour
{
public bool On = false;
public bool Off = true;
private float lerp = 0;

public string floatRangeProperty = "";//This allows you to type in the name of the property you want to animate in the inspector.

    public float cycleTime = 0;//This allows you to set the speed at which it animates.

   
void Update()
{

        ProceduralMaterial substance = renderer.material as ProceduralMaterial;//This finds the substance texture and allows you to use it.
       
if(On)
{
        if (substance)//Checks if this is a substance.
{
             lerp = Mathf.Repeat(Time.time * 2 / cycleTime, 11);
               substance.SetProceduralFloat(floatRangeProperty, lerp);//This sets the part of the substance you are controlling.
               substance.RebuildTextures();//This rebuilds the texture each update to make the changes.
            }
}

if(Off)
{
           substance.SetProceduralFloat(floatRangeProperty, 0);//This sets the part of the substance you are controlling.
           substance.RebuildTextures();//This rebuilds the texture each update to make the changes.

}


    }
}

My first guess would be that your Time variable in Unity is not reset correctly when you activate the effect.
Do you use $time in your substance or is it a simple animated parameter through a float ?

It is just animated though a float.

Ok, so definitely if it picks up where you left it, it means that your time variable is not reset correctly when you call the effect, try outputting the time value through a Debug.Log() to make sure the values are correct.