我使用Unity3d for android platform,
当我尝试在onRoomJoin
事件中展示游戏对象时,我收到如下错误。
get_gameObject can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
UnityEngine.Component:get_gameObject()
SFSConnect:OnRoomJoin(BaseEvent) (at Assets/SFSConnect.cs:861)
Sfs2X.Core.EventDispatcher:DispatchEvent(BaseEvent)
Sfs2X.SmartFox:DispatchEvent(BaseEvent)
Sfs2X.Controllers.SystemController:FnJoinRoom(IMessage)
Sfs2X.Controllers.SystemController:HandleMessage(IMessage)
Sfs2X.Core.SFSProtocolCodec:DispatchRequest(ISFSObject)
Sfs2X.Core.SFSProtocolCodec:OnPacketRead(ByteArray)
Sfs2X.Core.SFSIOHandler:HandlePacketData(ByteArray)
Sfs2X.Core.SFSIOHandler:OnDataRead(ByteArray)
Sfs2X.Bitswarm.BitSwarmClient:OnSocketData(Byte[])
Sfs2X.Core.ThreadManager:ProcessItem(Hashtable)
Sfs2X.Core.ThreadManager:InThread()
这是我的代码,如下所示:
public class SFSConnect : MonoBehaviour {
public GameObject obj;
void Start () {
img = obj.GetComponent<Image> ();
img.obj.SetActive (false);
}
void onRoomJoin(BaseEvent evt)
{
img.obj.SetActive (true);
}
}