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;
	}
}

 

Getting boored? Why not playing a game?

Power Block

Tiki Solitaire

Pet Connect

Cake Shop

Jewels Blitz 3

Forest Match

Bike Racing

Aquador

Solitaire Swift

Bubble Shooter Classic HD

Black and white snake

Leave a Reply

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