shenhuan111 2014-12-12 14:52 采纳率: 64.3%
浏览 6285
已采纳

C#在脚步中创建别的脚步类对象cs cs1=new cs();会有警告,如何消除

You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all
MonoBehaviour:.ctor()
cs:.ctor()
什么情况
You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all这个出现好几次

using UnityEngine;
using System.Collections;
public class csmouspo : MonoBehaviour {
cs cs1=new cs();
void Start(){
int i=this.cs1.cshs();
print ("r:"+i+"\n");
}

using UnityEngine;
using System.Collections;
public class cs : MonoBehaviour {
public int cshs() {
return 1; }
}

  • 写回答

5条回答

  • threenewbee 2014-12-12 15:41
    关注

    这个不是C#的错误,只能翻译下:
    你正在试图用new关键字创建一个MonoBehaviour,这是不允许的。MonoBehaviours只能通过AddComponent()被添加,或者,你的脚本可以从ScriptableObject继承或者根本没有基类。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制