为了完成学校任务,我需要制作一个基本的视频游戏。我正在尝试制作一个太空游戏的基本版本。
我想要一个包含多个天空盒子的数组,并且在启动游戏时,我希望游戏从该数组中随机选择一个天空盒子。这样你每次都会有一种在不同出生点的感觉。
有人可以帮助我吗?我在谷歌上找了很久,但没有找到任何有用的信息。
这些天空盒子位于名为“Assets/SkyBox Volume 2/DeepSpaceBlue”的文件夹中,文件名为 DSB。还有一个DeepSpaceGreen,文件名为DSG,以此类推。
这是我的当前代码,其中包含错误。
编辑:
错误:
我想要一个包含多个天空盒子的数组,并且在启动游戏时,我希望游戏从该数组中随机选择一个天空盒子。这样你每次都会有一种在不同出生点的感觉。
有人可以帮助我吗?我在谷歌上找了很久,但没有找到任何有用的信息。
这些天空盒子位于名为“Assets/SkyBox Volume 2/DeepSpaceBlue”的文件夹中,文件名为 DSB。还有一个DeepSpaceGreen,文件名为DSG,以此类推。
这是我的当前代码,其中包含错误。
编辑:
using UnityEngine;
using System.Collections;
public class RandomSkybox : MonoBehaviour
{
public Material[] materials;
// Use this for initialization
void Start()
{
skyBoxMaterial = materials[Random.Range(0, materials.length)];
RenderSettings.skybox = skyBoxMaterial;
}
// Update is called once per frame
void Update()
{
}
}
错误:
Severity Code Description Project File Line Suppression State
Error CS0103 The name 'skyBoxMaterial' does not exist in the current context SpaceRaiders.CSharp D:\Documenten\Unity\SpaceRaiders\Assets\Scripts\Space\RandomSkybox.cs 10 Active
Error CS1061 'Material[]' does not contain a definition for 'length' and no extension method 'length' accepting a first argument of type 'Material[]' could be found (are you missing a using directive or an assembly reference?) SpaceRaiders.CSharp D:\Documenten\Unity\SpaceRaiders\Assets\Scripts\Space\RandomSkybox.cs 10 Active
Error CS0103 The name 'skyBoxMaterial' does not exist in the current context SpaceRaiders.CSharp D:\Documenten\Unity\SpaceRaiders\Assets\Scripts\Space\RandomSkybox.cs 11 Active