美文网首页
Unity You are trying to create

Unity You are trying to create

作者: 114105lijia | 来源:发表于2022-05-12 15:05 被阅读0次

    在Unity中,继承于MonoBehavior的对象,要避免使用new关键字来创建,而必须使用AddComponent或Instantiate函数来创建

    之所以出现这个警告,是因为我们使用new方式来创建对象:

    PlayVideoTool playVideoTool = new PlayVideoTool();
    

    需要改成下面这样:

    playVideoTool = transform.gameObject.AddComponent<PlayVideoTool>();
    

    相关文章

      网友评论

          本文标题:Unity You are trying to create

          本文链接:https://www.haomeiwen.com/subject/syosurtx.html