- Home /
How can I add a speed factor to the script ?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.PostProcessing;
public class DOFControl : MonoBehaviour
{
public float maxMyValue = 10;
public float minMyValue = 0;
public float myValue = 10; // the total
public float changePerSecond = -1; // modify the total, every second
public float speed = 1f;
public PostProcessingProfile postProcProf;
private void Start()
{
StartCoroutine(DepthOfField());
}
private void Update()
{
}
IEnumerator DepthOfField()
{
while (true)
{
var dof = postProcProf.depthOfField.settings;
if (myValue == 0)
changePerSecond = 1;
if (myValue == 10)
changePerSecond = -1;
myValue = Mathf.Clamp(myValue + changePerSecond * Time.deltaTime, minMyValue, maxMyValue);
dof.aperture = myValue;
postProcProf.depthOfField.settings = dof;
yield return new WaitForSeconds(speed);
}
}
}
Maybe I should do it in the Update and not using StartCoroutine ?
If I will change the variable changePerSecond value for example to -10 then it will move faster but that's because it will jump over in 10's.
Instead I want it to keep changing by 1 or -1 but faster/slower.
But still very slow. When I change the speed value to 0.0001 it still seems like one second speed.
Your answer
Follow this Question
Related Questions
How do i change the GUI.Box font size and box size ? 0 Answers
How can i first destroy twice the objects then to create twice the objects ? 1 Answer
How can i rotate a transform using lerp but keep the nose in same direction/angle on x ? 1 Answer
How can i prevent from mouse to collide with thirdpersoncontroller ? 0 Answers
How can i pick two randomly items from gameobject array ? 1 Answer