首页 > 解决方案 > Unity c#我尝试执行方法时出错

问题描述

我有这个代码第一个文件

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Controller : MonoBehaviour
{
    public Machines machines;
    void Start()
    {
        machines = new Machines();
        machines.ClickSpeedUpgrade();//here I get the error
    }
}

第二个文件

using System.Collections;
using System.Collections.Generic;
using BreakInfinity;
public class Machines
{
    public void ClickSpeedUpgrade()
    {
        //some code
    }
}

NullReferenceException:对象引用未设置为对象的实例

为什么我会收到此错误,我该如何解决?

标签: c#unity3d

解决方案


推荐阅读