i was working on the lobby system for my game
Lobby lobby = await LobbyService.Instance.CreateLobbyAsync(lobbyName, maxPlayers, options);
Error - CS0029 Cannot implicitly convert type
'Unity.Services.Lobbies.Models.Lobby' to 'Lobby'
I don't know why it's showing this. It's the same as in the documentation
Trying to create a lobby with this code
Lobby lobby = await LobbyService.Instance.CreateLobbyAsync(lobbyName, maxPlayers, options);
I was expecting a lobby to be created.....
Related
I am writing an Unity editor script that creates TCP server accepts requests from other application, but I found out that "clicking" play mode reloads my editor scripts which will interrupts the connection by re-initializing my server. Is there any way Unity Editor can stop reloading this particular script and makes it up running at all time?
[InitializeOnLoadMethod]
static void InitializeOnLoadMethod()
{
if (m_Server == null)
{
EditorApplication.update += Update;
Debug.Log("starting");
IPAddress ip = IPAddress.Parse(ipAdress);
m_Server = new TcpListener(ip, port);
m_Server.Start();
Debug.Log("Sever started");
Debug.Log(ip);
Debug.Log(port);
//Wait for async client connection
m_Server.BeginAcceptTcpClient(ClientConnected, null);
OnServerStarted?.Invoke();
}
In other words, is there a way to keep all my static variables and my editor coroutines after PlayMode is invoked? I did some search and I think domain reloading has caused it
Haven't tried this and don't have Unity on this PC to test, but can you gate it by using the isPlaying check:
if (!Application.isPlaying)
{
// Do your server stuff here
}
https://docs.unity3d.com/ScriptReference/Application-isPlaying.html
In other words, don't run the code while the game is playing, which is true when you hit the Play button?
Currently i am developing the board game. There are four players, one is the actual human player and other remaining three is computer player or simply a bot.
When it is the turn of human player to throw the dice. He can throw and update the score and other thing.
But when it is the computer player turn i want everything to be updated such as throwing the dice updating score slowly so that player can see it.
What i am doing now is normal and after a human player turn, the computer player turn is updated in millisecond.
How can i do it so that it will be updated slowly and player can see it.
This is a very general question and without some code it's difficult to answer but there are two main options you can look into.
1) Convert your AI method into a coroutine and then add some "WaitForSeconds" in between.
IEnumerator YourMethod(){
// Do stuff
yield return new WaitForSeconds(time);
// Do stuff
yield return new WaitForSeconds(time);
// Do stuff
yield return new WaitForSeconds(time);
2) Break your Method into several methods and chain calls to one another at the end with Invoke
void YourMethod(){
// Do stufff
Invoke("YourMethod2", time);
void YourMethod2(){
// Do stuff
Invoke("YourMethod3", time);
In my project, I have two prefabs - One with a first person camera, and another one stripped of all it's first person components such as the mouselook, input controller, camera, and so on. My ultimate goal is to spawn my prefab with the camera on it and sending an rpc to spawn the dummy prefab on all other clients to sync up with my first person prefab. The problem I'm facing is when I try to send the rpc from my first person prefab's PhotonView, the rpc doesn't get called on other clients because the PhotonView id doesn't exist on other clients yet.
The following code is located on my NetworkManager script on an empty game object in the hierarchy.
void OnJoinedRoom(){
GameObject MyPlayer = (GameObject) Instantiate (FPSPlayer,spawnPoint.transform.position, spawnPoint.transform.rotation);
FPSPlayerPhotonView = MyPlayer.transform.root.gameObject.GetPhotonView();
int id = PhotonNetwork.AllocateViewID ();
FPSPlayerPhotonView.viewID = id;
FPSPlayerPhotonView.RPC("SpawnMyPlayerAsRemote", PhotonTargets.OthersBuffered,id, spawnPoint.transform.position, spawnPoint.transform.rotation);
}
[PunRPC]
void SpawnMyPlayerAsRemote(int id, Vector3 pos, Quaternion rot){
GameObject MyRemotePlayer = (GameObject)Instantiate (RemotePlayer, pos,rot);
RemotePlayerPhotonView = MyRemotePlayer.transform.root.gameObject.GetPhotonView();
RemotePlayerPhotonView.viewID = id;
}
This method is tested and will work.
What I suggest you do is create an empty player with NetworkView.
Create this player via PhotonNetwork.Instantiate so it will be instantiated inside all clients.
Check you are the owner of the networkview.
If you are, create all the client sided essentials (FPS Camera etc...).
If you aren't, create the dummy.
EDIT: I was wrong on the RPC part.
I am beginner to photon on unity3d. I want to move character synchronously in a game. I am attaching script as an observer to the photon view and using this code
void OnPhotonSerializeView(PhotonStream stream,PhotonMessageInfo info)
{
if (stream.isWriting)
{
Debug.Log("writing");
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
}
else
{
Debug.Log("reading");
this.correctPlayerPos = (Vector3)stream.ReceiveNext();
this.correctPlayerRot = (Quaternion)stream.ReceiveNext();
}
}
The problem is that the player who creates the room can change the position and rotation of player, it can only write. But the second player(who joins the rooms) cannot change the position and rotation,it can only read.
What can be the problem with my setup.
I have followed the marco polo tutorial(http://doc.exitgames.com/en/pun/current/tutorials/tutorial-marco-polo) for this. Any help is highly apperciated.
If you instantiate a GameObject per player via PhotonNetwork.Instantiate, then each client has it's own(ed) GameObject which this client can write updates for.
I am new to Unity3D. I am trying to do a simple thing. But not able to do this. I have a .obj file which is a 3d key file. I do the followings:
Import this key (to assets) in unity3D
Add this key to scene (from assets to hierarchy)
Add a script to this key
Add the OnMouseDown() function to this script as follows -
void OnMouseDown()
{
Debug.Log ("clicked...");
}
But when I click the key no message is showing in console. Please tell me what is the problem?
make sure the gameobject is not at layer "Ignore Raycast"
Use the following inside your update function to see raycasting is working fine.
void Update () {
if (Input.GetMouseButtonDown (0)) {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit)) {
Debug.Log ("Name = " + hit.collider.name);
Debug.Log ("Tag = " + hit.collider.tag);
Debug.Log ("Hit Point = " + hit.point);
Debug.Log ("Object position = " + hit.collider.gameObject.transform.position);
Debug.Log ("--------------");
}
}
}
The OnMouseDown and it's related functions are all actually older systems. The newer system to use for this is the event system.
Specifically to get mouse clicks you would implement this interface in a class:
http://docs.unity3d.com/460/Documentation/ScriptReference/EventSystems.EventTriggerType.PointerClick.html
But there is actually an easier way to do it without code.
Using this component:
http://docs.unity3d.com/ScriptReference/EventSystems.EventTrigger.html
You can then visually forward the mouse click event to something else.
If you don't fully follow what I have said so far, the thing to really start at is learning the UI system. You can find video tutorials here:
http://unity3d.com/learn/tutorials/modules/beginner/ui/ui-canvas
And just to make it clear, the UI system is not just for UI. The UI system runs off an EventSystem which is what you want to use to forward input events to any object 3D or 2D in the entire scene. The UI tutorials will explain the usage of that EventSystem.
You need to assign a collider to the 3d object if you want to fire it with OnMouseDown:
OnMouseDown is called when the user has pressed the mouse button while over the GUIElement or Collider.
This event is sent to all scripts of the Collider or GUIElement.
You can also do like by override click function
public override void OnPointerClick(PointerEventData data)
{
Debug.Log("OnPointerClick called.");
}