Difficulty connecting two Hololens with Unet - unity3d

I am relatively new to Unity and am currently trying to build an multi-user app on Hololens. Currently, I am just trying to get two Hololens to connect over LAN using Unet. When I use one of my Hololens to host the server, my laptop can connect to it during play mode in the Unity editor. However, when I try to use my other Hololens to connect to it, it does not work and I am not sure why. Does anyone else have this problem? And if so, how do you fix it?
Thanks in advance.
Edit: some code
Here's the code for network manager
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
using System;
public class NetworkManager_Custom : NetworkManager
{
public void StartupHost()
{
setPort();
NetworkManager.singleton.StartHost();
}
public void JoinGame()
{
SetIpAddress();
setPort();
NetworkManager.singleton.StartClient();
}
private void SetIpAddress()
{
string Address = "192.168.2.80";
NetworkManager.singleton.networkAddress = Address;
}
private void setPort()
{
NetworkManager.singleton.networkPort = 9001;
}
}
Here's the code for the start-server button
using HoloToolkit.Unity.InputModule;
using UnityEngine;
using UnityEngine.Networking;
public class ok : NetworkBehaviour, IFocusable, IInputClickHandler
{
bool hasFocus;
public NetworkManager_Custom manager;
public void OnFocusEnter()
{
hasFocus = true;
}
public void OnFocusExit()
{
hasFocus = false;
}
public void OnInputClicked(InputClickedEventData eventData)
{
manager.StartupHost();
}
}
Here's the code for joining server as client
using HoloToolkit.Unity.InputModule;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.Networking.NetworkSystem;
public class aegf : NetworkBehaviour, IFocusable, IInputClickHandler
{
bool hasFocus;
public NetworkManager_Custom manager;
public void OnFocusEnter()
{
hasFocus = true;
}
public void OnFocusExit()
{
hasFocus = false;
}
public void OnInputClicked(InputClickedEventData eventData)
{
manager.JoinGame();
}
}

It's worth double-checking the capabilties that you've set. Ensure all three of these are selected:
InternetClient
InternetClientServer
PrivateNetworkClientServer
Ref: https://learn.microsoft.com/en-us/uwp/schemas/appxpackage/appxmanifestschema/element-capability

Related

Creating an Inventory in Unity 3D - adapting from Oculus to HTC

I am trying to make a simple inventory in Unity 3D for virtual environment. I am using StemVR plugin, because I have HTC Vive. I was following this tutorial, made for Oculus (https://www.youtube.com/watch?v=gAz_SeDUQBk&t=310s) and now I have to adapt the code for HTC Vive, but I don't know how.
In the slot script I have a problem with this part of the script, where it should release an item after releasing a trigger:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Valve.VR;
public class Slot : MonoBehaviour
{
public GameObject ItemInSlot;
public Image slotImage;
void Start()
{
slotImage = GetComponentInChildren<Image>();
originalColor = slotImage.color;
}
private void OnTriggerStay(Collider other)
{
if (ItemInSlot != null) return;
GameObject obj = other.gameObject;
if (!IsItem(obj)) return;
if (OVRInput.GetUp(OVRInput.Button.SecondaryHandTrigger))
{
InsertItem(obj);
}
}
bool IsItem(GameObject obj)
{
return obj.GetComponent<Item>();
}
void InsertItem(GameObject obj)
{
obj.GetComponent<Rigidbody>().isKinematic = true;
obj.transform.SetParent(gameObject.transform, true);
obj.transform.localPosition = Vector3.zero;
obj.transform.localEulerAngles = obj.GetComponent<Item>().slotRotation;
obj.GetComponent<Item>().inSlot = true;
obj.GetComponent<Item>().currentSlot = this;
ItemInSlot = obj;
}
}
And in Inventory script I have a problem with adapting this part:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Valve.VR;
public class InventoryVR : MonoBehaviour
{
public GameObject Inventory;
public GameObject Anchor;
bool UIActive;
private void Start()
{
Inventory.SetActive(false);
UIActive = false;
}
private void Update()
{
if (OVRInput.GetDown(OVRInput.Button.Four))
{
UIActive = !UIActive;
Inventory.SetActive(UIActive);
}
}
}
What functions can I use to make this applicable for HTC Vive?

Assets\Script\Launcher.cs(23,26): error CS0115: 'Launcher.OnJoinedLobby()': no suitable method found to override

i am trying to make a multiplayer game by following a tutorial but i dont know why when i check from which is wrong i'm using photon free i also looked at the other forum but i can't solve
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class Launcher : MonoBehaviourPunCallbacks
{
// Start is called before the first frame update
void Start()
{
Debug.Log("Connecting to Master");
PhotonNetwork.ConnectUsingSettings();
}
public override void OnConnectedToMaster()
{
Debug.Log("Connected to Master");
PhotonNetwork.JoinLobby();
}
public override void OnJoinedLobby()
{
Debug.Log("Joined Lobby");
}
// Update is called once per frame
void Update()
{
}
}

Unity The name 'PrefabUtility' does not exist in the current context

I'm trying to build a Unity game, and keep getting the error:
Assets\charaterselection.cs(34,9): error CS0103: The name 'PrefabUtility' does not exist in the current context
The issue is I imported UnityEditor, I'm not sure what's going on
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.SceneManagement;
public class charaterselection : MonoBehaviour
{
public SpriteRenderer sr;
public List<Sprite> skins = new List<Sprite>();
private int selecectedSkin;
public GameObject player;
public void Next()
{
selecectedSkin=selecectedSkin+1;
if (selecectedSkin== skins.Count)
{
selecectedSkin=0;
}
sr.sprite= skins[selecectedSkin];
}
public void back()
{
selecectedSkin = selecectedSkin - 1;
if (selecectedSkin < 0)
{
selecectedSkin = skins.Count - 1;
}
sr.sprite = skins[selecectedSkin];
}
public void play()
{
PrefabUtility.SaveAsPrefabAsset(player, "Assets/Players/FROGY.prefab");
SceneManager.LoadScene(1);
}
}
Thank you guys for your help, I literately just made a file called "Editor" and it worked.

Photon 2 Can´t join random room

I´m new to Networking and can´t find the problem on my self.
I made a matchmaking system for my game and it worked well.
But after some changes in my Game it stopped working.
It should create a room if no room is there. Else join a random room.
But it always creates a new room. no errors etc.
here are the scripts that should do the work.
Edit:
broke it down to this script:
using Photon.Pun;
using Photon.Realtime;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PhotonLobby2 : MonoBehaviourPunCallbacks
{
public static PhotonLobby2 lobby;
public GameObject battlebutton;
private void Awake()
{
lobby = this; // create singleton
}
void Start()
{
PhotonNetwork.ConnectUsingSettings();
}
public override void OnConnectedToMaster()
{
Debug.Log("connected to masterserver");
PhotonNetwork.AutomaticallySyncScene = true;
battlebutton.SetActive(true);
}
public void OnBattleButtonClicked()
{
PhotonNetwork.JoinRandomRoom();
}
public override void OnJoinRandomFailed(short returnCode, string message)
{
Debug.Log(message + returnCode);
Debug.Log(" failed to join random game");
CreateRoom();
}
void CreateRoom()
{
PhotonNetwork.CreateRoom("Room");
}
public override void OnCreatedRoom()
{
Debug.Log("Created Room");
base.OnCreatedRoom();
}
public override void OnPlayerEnteredRoom(Player newPlayer)
{
Debug.Log("Entered");
base.OnPlayerEnteredRoom(newPlayer);
}
}
Debug says: No match found32760
It is because the two players join matches in different regions... you can force this in the photon server settings Fill in Dev region and Fixed region with one particular server region that has better ping for you. Make the property Use sure name serve is also checked
I resolved this issue by checking the room properties which first player creates.
There is a variable of Room named "IsOpen". If it is false then second player cannot join the same room. I just set it to true and now its perfectly joining the same room.

Unity monodevelop, if activate gameobject run script

Hello I will actually keep this short.I butchered this piece of code. I can't find the solutions.
My code
using UnityEngine;
using System.Collections.Generic;
using UnityEngine.UI;
public class Linkbutton : MonoBehaviour{
void Update()
{
if (GameObject.activeSelf)
public void LinkFunc();
{
Application.OpenURL ("https://stolpersteinecoevorden.jimdo.com/stolpersteine/"); running = false;
}
}
}
The errors I'm having
I have been trying stuff for hours without a solution in view.
Thanks in advance
Try this:
public class Linkbutton : MonoBehaviour
{
bool running = true;
void Update()
{
if (this.gameObject.activeSelf)
LinkFunc();
}
public void LinkFunc()
{
Application.OpenURL("https://stolpersteinecoevorden.jimdo.com/stolpersteine/");
running = false;
}
}