Hi, I’m having issues with Mathf.MoveTowards. I want to interpolate between 1 and 0 over time with a public float “fadeValue”. But the console yields jumpy results from 1, 0, randomly increasing and decreasing till it reaches 0 eventually.
using UnityEngine;
using System.Collections;
public class CloudBehaviour : MonoBehaviour {
public float cloudSpeed = 1;
public float cloudScaleMin = 1;
public float cloudScaleMax = 1;
[Range(0f, 355f)]
public float rotationThreshould;
public float fadeValue = 10;
private MeshRenderer meshrenderer;
private float cloudScale;
private float fade;
// Use this for initialization
void Start () {
meshrenderer = GetComponent<MeshRenderer>();
cloudScale = Random.Range(cloudScaleMin, cloudScaleMax);
transform.localScale += new Vector3(cloudScale, cloudScale, cloudScale);
transform.Rotate(0f, Random.Range(0f, rotationThreshould), 0f);
}
// Update is called once per frame
void Update () {
transform.position += new Vector3(cloudSpeed * Time.deltaTime, 0f, 0f);
fade = Mathf.MoveTowards(1f, 0f, fadeValue * Time.deltaTime);
meshrenderer.material.SetFloat("_AlphaLevel", fade);
Debug.Log(fade);
}
}