Mathf.Lerp not working.
Mathf.lerp does not show the effect whenever i hit play, here is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.ImageEffects;
public class DepthOfFeild_Manager : MonoBehaviour {
[Header("References")]
public DepthOfField DepthOfFieldObject;
[Header("Values")]
public float blurSpeed;
public float FocalSize = 0f;
private float focalSizeZeroValue = 2f;
private void Start()
{
DepthOfFieldObject = GetComponent<DepthOfField>();
DepthOfFieldObject.focalSize = focalSizeZeroValue;
}
private void Update()
{
if(PauseGame.GameIsPaused == true)
{
DepthOfFieldObject.enabled = true;
DepthOfFieldObject.focalSize = Mathf.Lerp(FocalSize, focalSizeZeroValue, Time.deltaTime * blurSpeed);
}
else
{
DepthOfFieldObject.enabled = false;
DepthOfFieldObject.focalSize = Mathf.Lerp(focalSizeZeroValue, FocalSize, Time.deltaTime * blurSpeed);
}
}
}
The third value of $$anonymous$$athf.Lerp is a value between 0 and 1, to 'merge' between two numbers. If you give it a small value every frame then it will always stay mostly equal to the first argument
Answer by Pinkuboxu · May 11, 2018 at 02:55 PM
You need a blur += blurSpeed * Time.deltaTime; somewhere in Update and use that instead of blurSpeed as the amount of interpolation. It's taking in the same value if blurSpeed isn't changing, so you get the same result each frame. You will also want to make sure blur is never > 1 and resets to 0 when you want to do the blur again.
... or perhaps just set up an animator with two animations to change the blur value with keys and curves. A lot of people either don't seem to like using animations to control public fields or maybe don't know that they can?
Answer by unity_21erushbrook · May 11, 2018 at 10:32 AM
You should add a Debug.Log where the Mathf.Lerp is to make sure it’s running. If it’s not then run through what could be causing that.
Your answer
Follow this Question
Related Questions
Mathf.Lerp for integers 1 Answer
Min and Max value? 1 Answer
Use blur on different layers? 0 Answers
Unit Circle Coordinates 0 Answers