对于学校任务,我必须制作一个基本的视频游戏。我正在尝试制作太空游戏的基本版本。
我想要一个包含多个天空盒的数组,并且在启动游戏时,我希望游戏从数组中选择一个随机的天空盒。这样你就会有一种感觉,你每次都在不同的重生点。
谁能帮我?我一直在谷歌上寻找,但我找不到任何有用的东西。
天空盒位于一个名为:
- 'Assets/SkyBox Volume 2/DeepSpaceBlue' 文件名 = DSB
- 'Assets/SkyBox Volume 2/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