对于学校任务,我必须制作一个基本的视频游戏。我正在尝试制作太空游戏的基本版本。我想要一个包含多个天空盒的阵列,并且在启动游戏时,我希望游戏从阵列中选择一个随机的天空盒。这样,您将感觉每次都处于不同的生成位置。谁能帮我?我一直在寻找谷歌,但找不到任何有用的东西。天空盒位于以下文件夹中:'资产/ SkyBox卷2 / DeepSpaceBlue'文件名= DSB'资产/ SkyBox卷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 StateError CS0103 The name 'skyBoxMaterial' does not exist in the current context SpaceRaiders.CSharp D:\Documenten\Unity\SpaceRaiders\Assets\Scripts\Space\RandomSkybox.cs 10 ActiveError 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 ActiveError CS0103 The name 'skyBoxMaterial' does not exist in the current context SpaceRaiders.CSharp D:\Documenten\Unity\SpaceRaiders\Assets\Scripts\Space\RandomSkybox.cs 11 Active 最佳答案 public Skybox[] skyBoxes;你必须将项目拖到数组中就这么简单。在检查器中,将长度设置为“ 5”,然后将五个项目拖入其中。仅此而已。也是您发布的最新版本,skyBoxMaterial = materials[Random.Range(0, materials.length)];您忘记了声明变量。就这么简单。Material skyBoxMaterial;skyBoxMaterial = materials[Random.Range(0, materials.length)];对于“长度”,显然是“长度”。不要忘记List ,它是.Count而不是.Length。
10-08 11:35