ItArth
1
I have this script i whant that when the SkyType enum is in cloudy the cloudMaterial float “CutOff” increase exponentially to 1 and when the enum its in sunny the CutOff decrease to 0
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RainSystem : MonoBehaviour
{
public enum SkyType { Sunny,Cloudy};
public SkyType skyType;
public Material cloudMaterial;
private void Start()
{
}
void Update()
{
switch (skyType)
{
case SkyType.Cloudy:
Cloudy();
break;
case SkyType.Sunny:
Sunny();
break;
}
}
void Cloudy()
{
cloudMaterial.SetFloat("_CutOff", 1);
}
void Sunny()
{
cloudMaterial.SetFloat("_CutOff", 0);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RainSystem : MonoBehaviour
{
public enum SkyType { Sunny,Cloudy};
public SkyType skyType;
public float changeSpeed = 1;
private float sunny;
public Material cloudMaterial;
private void Start()
{
sunny = cloudMaterial.GetFloat("_CutOff");
}
void Update()
{
switch (skyType)
{
case SkyType.Cloudy:
Cloudy();
break;
case SkyType.Sunny:
Sunny();
break;
}
}
void Cloudy()
{
sunny = Mathf.MoveTowards(sunny, 1, changeSpeed * Time.deltaTime);
cloudMaterial.SetFloat("_CutOff", sunny);
}
void Sunny()
{
sunny = Mathf.MoveTowards(sunny, 0, changeSpeed * Time.deltaTime);
cloudMaterial.SetFloat("_CutOff", sunny);
}
}