Unity中遇到以下错误:Can’t add script behaviour Interactable. The script class can’t be abstract!
我正在搭建一个射线投射的设置,让游戏物体在点击/触摸时运行代码。
if (Physics.Raycast(transform.position, transform.forward, out RaycastHit hit, maxDistance, interactableLayers))
{
if (Input.GetButtonDown("Fire1"))
{
if (hit.collider != null)
{
currentInteractable = hit.collider.GetComponent<Interactable>();
Debug.Log(hit.collider.name);
}
}
我跟着一个教程做的,必须使用接口来配置每个游戏对象的OnClick动作:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// public class Interactable : MonoBehaviour
// {
public interface Interactable
{
void onClickAction();
}
然而,我遇到了一堆错误!我无法将这个可交互脚本添加到游戏对象中,并收到以下错误提示:“Can’t add script behaviour Interactable. The script class can’t be abstract!”
我还在控制台中看到了以下信息:”Interactable is missing the class attribute ExtensionOfNativeClass!”
请问为什么会这样?
共以下 1 个回答