Hi, I want to know is there a way of using Mathf.SmoothStep to control the float of a variable? You see I downloaded this [package][1] on unity assets store and created a IEnumerator OnTriggerEnter2D (in a new script) to control the effect once my player hits an orb, making it slow down but now I want to add an animation. Rather than having it appear of the screen and then disappearing, I want to make the frost effect slowly come in, kinda like controlling the frost amount in the inspector. It is possible, because I tried doing it like this:
(This is attach to orb)
// Use this for initialization
void Start () {
}
IEnumerator OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player") {
//frost.enabled = true;
GameObject.Find("Main Camera").GetComponent().enabled = true;
FrostEffect.valToBeLerped = Mathf.SmoothStep(0, 1f, FrostEffect.FrostAmount);
yield return new WaitForSeconds (1.01f);
FrostEffect.valToBeLerped = Mathf.SmoothStep(1, 0, FrostEffect.FrostAmount);
GameObject.Find("Main Camera").GetComponent().enabled = false;
}
}
But it's still appearing automatically rather than it slowly coming in like an animation. Anyway this is the frost effect script I downloaded from the assets store:
(Attach to the main camera)
public static float FrostAmount = 0.3f; //0-1 (0=minimum Frost, 1=maximum frost)
public static float valToBeLerped = 0;
public float EdgeSharpness = 1; //>=1
public float minFrost = 0; //0-1
public float maxFrost = 1; //0-1
public float seethroughness = 0.2f; //blends between 2 ways of applying the frost effect: 0=normal blend mode, 1="overlay" blend mode
public float distortion = 0.1f; //how much the original image is distorted through the frost (value depends on normal map)
public Texture2D Frost; //RGBA
public Texture2D FrostNormals; //normalmap
public Shader Shader; //ImageBlendEffect.shader
private Material material;
private void Awake()
{
material = new Material(Shader);
material.SetTexture("_BlendTex", Frost);
material.SetTexture("_BumpMap", FrostNormals);
}
private void OnRenderImage(RenderTexture source, RenderTexture destination)
{
if (!Application.isPlaying)
{
material.SetTexture("_BlendTex", Frost);
material.SetTexture("_BumpMap", FrostNormals);
EdgeSharpness = Mathf.Max(1, EdgeSharpness);
}
material.SetFloat("_BlendAmount", Mathf.Clamp01(Mathf.Clamp01(FrostAmount) * (maxFrost - minFrost) + minFrost));
material.SetFloat("_EdgeSharpness", EdgeSharpness);
material.SetFloat("_SeeThroughness", seethroughness);
material.SetFloat("_Distortion", distortion);
///Debug.Log("_Distortion: "+ distortion);
Graphics.Blit(source, destination, material);
}
Thank you. :)
[1]: https://www.assetstore.unity3d.com/en/#!/content/5337
↧