Unity和C#问题。脚本错误。有人知道如何解决此问题吗?

时间:2019-12-04 11:10:47

标签: c# unity3d 2d

enter image description here因此,我开始使用Unity制作游戏(知识非常有限)。

它是2D游戏。我创建了一个用于健康,食品.. ETC ..

的脚本

一旦我尝试将其加载为统一,就会出现以下错误?

'无法添加脚本组件'Game Manag',因为找不到脚本类。确保没有编译错误,并且文件名和类名匹配。

有什么想法吗?

https://i.imgur.com/mhEodFW.jpg

enter image description here

1 个答案:

答案 0 :(得分:1)

好的,看起来您的代码中有很多错误。您必须在此处发布代码,请勿发布屏幕截图。首先,我要说说创建一个名称为GameManager的新脚本。确保游戏和管理器之间没有空格。其次,您的Debug.Log也会引发错误。

我已更正了这些错误,并在下面发布了您的无错误代码:

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

public class GameManager : MonoBehaviour {
    int Health;
    int Day;
    int Food;
    int Money;
    // Use this for initialization
    void Start () {
        Health = 100;
        Food = 100;
        Day = 0;
        Money = 0;

        Debug.Log(Health);
    }

    // Update is called once per frame
    void Update () {

    }
}