[英]the script don't inherit a native class that can manage a script unity
我是 c# 和 Unity 的初學者程序員。 所以我正在為我的游戲制作一個網格系統,當我嘗試將我的統一項目中的每個腳本添加為組件時,它會打印一個錯誤:“腳本不繼承可以管理腳本的本機 class”我不知道我需要做什么。如果可以請幫助我
/////////第一個腳本//////////////
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()
{
}
}
您的第一個腳本被命名為“網格”而不是“網格”。
第二個腳本:
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
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.