Hi guys,
I am trying to change Fog Color at runtime but cant’ get it to work.
The following code works when i choose one of the main color like red, green, blue etc… but can’t use it when it comes to using hexcode.
public class ExampleClass : MonoBehaviour {
void Example() {
RenderSettings.fogColor = Color.blue;
RenderSettings.fog = true;
}
}
The color i want fog to change to at runtime is light blue and the hex color code is 4CA7E6FF.
Is there a way i can make this to work?
Thanks
You need to try to parse the Hex string, to convert it to a color
Color newCol;
bool bConverted = ColorUtility.TryParseHtmlString("#4CA7E6FF", out newCol);
//Did it successfully parse the Hex?
if (bConverted) {
RenderSettings.fogColor = newCol;
}
Thanks.
I tried the above method, but I can’t seem to get it to work when i add bConverted line. I am using the attached code below to change the fogcolor and enable a skybox onTrigger with Player.
using UnityEngine;
using System.Collections;
public class SkyboxchangeC : MonoBehaviour {
public Material otherSkybox;
public Color newCol;
bool bConverted = ColorUtility.TryParseHtmlString("#4CA7E6FF", out newCol);
void OnTriggerEnter(Collider other)
{
if (other.tag == "Player" && RenderSettings.skybox != otherSkybox && bConverted)
RenderSettings.skybox = otherSkybox;
RenderSettings.fog = true;
RenderSettings.fogColor = newCol;
}
}