分类: IT业界
2014-03-18 11:04:43
天空变换代码
个人作法:
1、建立一个 camera , GameObject-->Create other-->camera
2、於camera建立一个 skybox ,component-->Rendering-->skybox
3、於main camera 也建立一个skybox
4、分别拉天空白天与黄昏材质球於camera、main camera的skybox
5、拉script於main camera , 再拉camera 物件於cammer
即可切换
以下是c# script 程式码
using UnityEngine;
using System.Collections;
public class changesky : MonoBehaviour {
//宣告GameObject物件
public GameObject cammer;
private int sky = 0;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.A))
{
sky++;
if (sky == 1)
{
cammer.SetActiveRecursively(false);
}
else if (sky == 2)
{
cammer.SetActiveRecursively(true);
}
if (sky == 3)
{
sky = 0;
}
}
}
}