Changing the skybox material programmatically in Unity

I’m using this simple script after attaching it to UI Buttons to change my skybox materials. Let’s say we have two skybox materials with two UI Buttons to switch between them.

Here is the script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ChangeSky : MonoBehaviour {

	public Material sky1;
	public Material sky2;

	public void SkyOne(){
		RenderSettings.skybox = sky1;

	public void SkyTwo(){
		RenderSettings.skybox = sky2;



Leave a Reply

Your email address will not be published. Required fields are marked *