1
0
mirror of synced 2024-12-14 15:22:54 +01:00
WACVR/Assets/Script/SkyboxSwitcher.cs

49 lines
1.4 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class SkyboxSwitcher : MonoBehaviour
{
[SerializeField]
private List<Material> skyboxes;
[SerializeField]
private int currentSkyboxIndex; // should start at 0
[Header("Components")]
[SerializeField]
private PanelButton incrementBtn;
[SerializeField]
private PanelButton decrementBtn;
[SerializeField]
private TextMeshPro counterTxt;
// Start is called before the first frame update
void Start()
{
incrementBtn.ButtonPressed += IncrementEvent;
decrementBtn.ButtonPressed += DecrementEvent;
//skyboxes.Insert(0, Resources.Load<Material>("unity_builtin_extra/Default-Skybox")); // results in plain blue??? not the ubiquitous unity default
skyboxes.Insert(0, RenderSettings.skybox); // add ubiquitous default skybox (should be current)
SetSkybox();
}
private void IncrementEvent()
{
currentSkyboxIndex = (currentSkyboxIndex + 1) % skyboxes.Count;
SetSkybox();
}
private void DecrementEvent()
{
if (--currentSkyboxIndex < 0)
currentSkyboxIndex = skyboxes.Count - 1;
SetSkybox();
}
private void SetSkybox()
{
counterTxt.text = (currentSkyboxIndex + 1).ToString();
2022-05-26 00:04:33 +02:00
if (skyboxes[currentSkyboxIndex] != null)
RenderSettings.skybox = skyboxes[currentSkyboxIndex];
}
}