小编Tky*_*Stm的帖子

在Unity中的另一个类中从Dictionary接收值

我想创建一个GameLoader来加载我的精灵,然后创建一个SceneController来创建游戏对象.我将精灵存储在GameLoader的字典中,以获取我想要创建函数的精灵,以从GameLoader接收特定的精灵.当它在一个类中时它正在工作但是现在它是两个类我在获取Sprite时遇到了问题.我收到这个错误

NullReferenceException: Object reference not set to an instance of an object
SceneController.createGeometry () (at Assets/Controllers/SceneController.cs:18)
SceneController.Start () (at Assets/Controllers/SceneController.cs:13)
Run Code Online (Sandbox Code Playgroud)

SceneController.cs

using System;
using System.Linq; 
using UnityEngine;
using System.Collections.Generic;

public class SceneController : MonoBehaviour {
    string[] geometryObjects = { "cube", "cube", "circle", "circle", "cube_small" };
    int objectCount = 5;
    GameLoader gameLoader;

    void Start () {
        createGeometry();
    }

    void createGeometry() {
        foreach (string geometryObject in geometryObjects) {
            Debug.Log(gameLoader.getGeometrySprite(geometryObject));
            GameObject geometryGameObject = new GameObject();
            geometryGameObject.name = geometryObject;
            geometryGameObject.tag = "Geometry";
            geometryGameObject.transform.position = …
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine

1
推荐指数
1
解决办法
180
查看次数

标签 统计

c# ×1

unity-game-engine ×1