问题描述
我是 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()
{
}
}
解决方法
您的第一个脚本名为“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
}
}