- Home /
Question by
Stillborn · Apr 25, 2014 at 12:56 AM ·
c#networkviewinitialization
My Code isnt Initializing networkview with its own Connected Peer
Im having issues with if(networkView.isMine == true) Well Some reason my client is Telling the networkview that it isnt mine and ignoring my request For the spawn Menu Ass if i remove it Everything works fine .. one connected peer but if i do a second connection My first connect is Duplicated and sent back to the spawn screen.. but is able to use chat and when they click respawn neither of player one or Player two see one another Here my code for the client .. not much ont eh server side but File Read and Writes.. and RPC sent back to client for Verification Accept ETC.. But here code help me Figure this out Sorry if its been on here millions of times but I havent seen an answer for it as of yet
using UnityEngine;
using System.Collections;
using System;
using System.Text;
using System.IO;
public class ClientScript : MonoBehaviour {
public Transform MalePrefab;
public Transform FemalePrefab;
private int MaxNameSize = 25;
private int MaxPassSize = 25;
private string userName = "Username";
private string userPass = "Password";
private string userEmail = "Enter Email Here";
public string ClientName = "Speed Hackers";
public static string netClientVersion = "0.1";
public int netServerPort = 16500;
public Texture MenuBGLogin;
public Texture SpawnBG;
// private int BGWidth = -100;
// private int BGHeight = -30;
// private int BGSizeWidth = 207;
// private int BGSizeHeight = 206;
private int RTextBoxSW = 120;
private int RtextBoxW = -455;
private int RtextBoxW1 = -25;
private int RtextBoxW2 = -50;
private int RegButton = -80;
private int UNLabelW = -460;
private int UNLabelH = 3;
private int UNLabelSizeW = 145;
private int UNLabelSizeH = 25;
private int RbuttonW = 80;
private int ButtonW = -160;
private int ButtonW2 = 5;
private int ButtonH = 2;
private int ButtonWSize = 75;
private int ButtonHSize = 25;
// private int UpdateW = 200;
// private int UpdateH = 200;
// private int UpdateSW = 200;
// private int UpdateSH = 200;
public bool SpawnScreenEnabled = false;
public bool DisableOnGUI = false;
public bool isClientConnected = false;
public bool isRegisterEnabled = false;
public bool connectedPlayer = false;
public bool iAmSpawned = false;
//public bool versionCheck = false;
void Start ()
{
userName = PlayerPrefs.GetString("Username");
}
void OnGUI()
{
AccountRegistration ();
if (Network.peerType == NetworkPeerType.Disconnected)
{ // If the server is disconnected.
if(isClientConnected == false)
{
Connect();
isClientConnected = true;
}
}
else
{
if(isRegisterEnabled == false && SpawnScreenEnabled == false && DisableOnGUI == false)
{
GUI.DrawTexture(new Rect(0,0,Screen.width,Screen.height),MenuBGLogin);
GUI.BeginGroup(new Rect(0,Screen.height/1-35,Screen.width,50));
userName = GUI.TextField(new Rect(Screen.width/1 + UNLabelW,UNLabelH,UNLabelSizeW,UNLabelSizeH),userName,MaxNameSize);
userPass = GUI.TextField(new Rect(Screen.width/1 + UNLabelW+150,UNLabelH,UNLabelSizeW,UNLabelSizeH),userPass, MaxPassSize);
GUI.Box(new Rect(0,0,Screen.width,30),ClientName);
if(GUI.Button(new Rect(Screen.width/1 + ButtonW,ButtonH,ButtonWSize,ButtonHSize),"Login"))
{
LogPlayerIn(userName,userPass);
}
if(GUI.Button(new Rect(Screen.width/1 + ButtonW + RbuttonW,ButtonH,ButtonWSize,ButtonHSize),"Register"))
{
isRegisterEnabled = true;
}
if(GUI.Button(new Rect(ButtonW2,ButtonH,ButtonWSize,ButtonHSize),"Quit"))
{
Application.Quit();
}
GUI.EndGroup();
}
}
if (SpawnScreenEnabled == true)
{
if(networkView.isMine == true)
{
GUI.DrawTexture(new Rect(0,0,Screen.width,Screen.height),SpawnBG);
GUI.contentColor = Color.blue;
transform.position += Vector3.up *15* Time.deltaTime;
GUI.BeginGroup(new Rect(Screen.width/2 -140, Screen.height/2+250, 185, 50));
GUI.Box(new Rect (-10,0,200,50),"Character Selection");
if (GUI.Button (new Rect (5, 20, ButtonWSize, ButtonHSize), "Male")) {
Network.Instantiate (MalePrefab, new Vector3 (0,40f,0),transform.rotation,0);
SpawnScreenEnabled = false;
DisableOnGUI = true;
connectedPlayer = true;
iAmSpawned = true;
}
if (GUI.Button (new Rect (105, 20, ButtonWSize, ButtonHSize), "Female")) {
Network.Instantiate (FemalePrefab, new Vector3 (0,40f,0),transform.rotation,0);
SpawnScreenEnabled = false;
DisableOnGUI = true;
connectedPlayer = true;
iAmSpawned = true;
}
GUI.EndGroup ();
}
else
{
enabled = false;
}
}
}
public void LogPlayerIn(string userName, string userPass)
{
PlayerPrefs.SetString("Username", userName);
networkView.RPC("Login",RPCMode.Server,userName,userPass,Network.player);
}
public void RegPlayerIn(string userName, string userPass, string userEmail)
{
PlayerPrefs.SetString("Username", userName);
networkView.RPC("Register",RPCMode.Server,userName,userPass,userEmail,Network.player);
}
void OnPlayerDisconnected (NetworkPlayer player)
{
Debug.Log("Server destroying player");
Network.RemoveRPCs(player, 0);
Network.DestroyPlayerObjects(player);
}
public void AccountRegistration()
{
if(isRegisterEnabled == true && SpawnScreenEnabled == false && DisableOnGUI == false)
{
GUI.DrawTexture(new Rect(0,0,Screen.width,Screen.height),MenuBGLogin);
GUI.BeginGroup(new Rect(0,Screen.height/1-35,Screen.width,50));
userName = GUI.TextField(new Rect(Screen.width/1 + RtextBoxW,UNLabelH,RTextBoxSW,UNLabelSizeH),userName,MaxNameSize);
userPass = GUI.TextField(new Rect(Screen.width/1 + RtextBoxW+150 + RtextBoxW1,UNLabelH,RTextBoxSW,UNLabelSizeH),userPass,MaxPassSize);
userEmail = GUI.TextField(new Rect(Screen.width/1 + RtextBoxW+300 + RtextBoxW2,UNLabelH,RTextBoxSW,UNLabelSizeH),userEmail);
GUI.Box(new Rect(0,0,Screen.width,30),ClientName);
if(GUI.Button(new Rect(Screen.width/1 + RegButton,ButtonH,ButtonWSize,ButtonHSize),"Register"))
{
RegPlayerIn(userName,userPass,userEmail);
isRegisterEnabled = false;
}
if(GUI.Button(new Rect(ButtonW2,ButtonH,ButtonWSize,ButtonHSize),"Cancel"))
{
isRegisterEnabled = false;
}
GUI.EndGroup();
}
}
String ServerPath;
String ClientPaths;
public string netServerAddress = "";
public string ServerIpAddress = "";
void Connect()
{
ClientPaths = "/NetAddress/" + "netServerAddress" + ".INI";
ServerPath = Application.dataPath + ClientPaths;
if (File.Exists(ServerPath))
{
var lines = File.ReadAllLines(ServerPath);
foreach(var line in lines)
{
// It Reads the client directory for a file with Server Ip
if(line.Contains("ServerIp = "))
{
ServerIpAddress = line.Replace("ServerIp = ","");
Network.Connect(ServerIpAddress,netServerPort);
//Application.LoadLevel("ClientUpdater");
Debug.Log ("No Server With Ip = " + ServerIpAddress + " Is Available!");
}
}
}
}
[RPC]
public void SendErrorMessage(string uUserName,string uPassword,string uEmail,NetworkPlayer player)
{
GUI.Label(new Rect(0,0,100,100),"Username Is Already Taken " + uUserName);
Debug.LogError ("Username Already Taken " + uUserName);
}
[RPC]
public void Register(string Username,string Userpass,string Email,NetworkPlayer player)
{
}
[RPC]
public void Login(string Username,string Userpass,NetworkPlayer player)
{
}
[RPC]
public void LoginRequest(string Username,string Password,NetworkPlayer player)
{
SpawnScreenEnabled = true;
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613143523im_/https://answers.unity.com/themes/thub/images/avi.jpg)