Change ambientmode using c sharp
I'm trying to change the environment lighting source in game from a hdri to a color.
I figured this was the "ambientMode" but i have no idea how i change it.
Ideally i want a dropdown menu on a gameobject to drive the dropdown menu in the lighting panel.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
using UnityEngine;
using System.Collections;
public class TestScript : MonoBehaviour {
public enum EnvLightSource { Skybox, Trilight, Flat, Custom }
public EnvLightSource lSource;
public string test;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
test = lSource.ToString();
/// RenderSettings.ambientMode = ??? what here
}
}
Answer by Cuttlas-U · Mar 09, 2018 at 12:48 PM
hi;
i think u need this code :
RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Skybox;
also u can change it from Windoes > Lightning
Thank you very much! Just figured it out myself, but thanks anyway! :)
Answer by kilianmooder · Mar 09, 2018 at 12:49 PM
Figured it out myself, probably not the most beautiful solution:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
using UnityEngine;
using System.Collections;
public class ExampleScript : MonoBehaviour {
public enum EnvLightSource { Skybox, Trilight, Flat }
public EnvLightSource lSource;
void Update () {
if (lSource == EnvLightSource.Skybox)
{
RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Skybox;
}else if (lSource == EnvLightSource.Flat)
{
RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Flat;
}else if (lSource == EnvLightSource.Trilight)
{
RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Trilight;
}
}
}
Your answer
Follow this Question
Related Questions
See Light through fog 0 Answers
Adding target image above random gameobject (enemy) 0 Answers
Trouble with DontDestroyOnLoad 1 Answer
2D shader / lighting like Terraria or Starbound 2 Answers
1 Restart Scene multiple levels. Is this possible? - C# - 1 Answer