脚本不继承可以管理脚本统一的本机类

时间:2021-01-16 21:05:57

标签: c# unity3d grid-system

我是 C# 和 Unity 的初级程序员。 所以我正在为我的游戏制作一个网格系统,当我尝试将我的统一项目中的每个脚本添加为组件时,它会打印一个错误:“脚本没有继承可以管理脚本的本机类” 我不知道我需要做什么。如果可以,请帮助我

//////////第一个脚本////////////////

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

public class Gird1 : MonoBehaviour
{
    private int width;
    private int height;
    private int[,] gridArray;

    public Gird(int width, int height)
    {
        this.width = width;
        this.height = height;
        gridArray = new int[width, height];
        Debug.Log(width + " " + height);
      }
}

////////第二个脚本////////////////////

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

public class Testing : MonoBehaviour
{

   private void Start()
   {
       Grid grid = new Grid(20, 10);
   }


   void Update()
   {

   }
}

image of grid

1 个答案:

答案 0 :(得分:0)

您的第一个脚本名为“Gird”而不是“Grid”。

第二个脚本:

public class Testing : MonoBehaviour
{
   public Gird1 gird1; // Assign in the inspector. We need an instance of Gird1

   private void Start()
   {
       if (gird1 == null) { // In case someone forgot to assign in the inspector
           gird1 = (Gird1)FindObjectOfType(typeof(Gird1)); // .. We'll search the scene
       }
       gird1.Gird(20,10); // Call the Gird() function on your gird1 instance
   }
}