在Unity中,继承于MonoBehavior的对象,要避免使用new关键字来创建,而必须使用AddComponent或Instantiate函数来创建
之所以出现这个警告,是因为我们使用new方式来创建对象:
PlayVideoTool playVideoTool = new PlayVideoTool();
需要改成下面这样:
playVideoTool = transform.gameObject.AddComponent<PlayVideoTool>();
在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
网友评论