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 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用
  • ¥15 kafka topic 所有分副本数修改
  • ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
  • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?
  • ¥40 串口调试助手打开串口后,keil5的代码就停止了