Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Initialising List array for use in a custom Editor 1 Answer

Call StartCoroutine() from inside a function other than Start!? 2 Answers

Pause Game When Function Is Enabled? 3 Answers

how can i auto target Gameobject on startup 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges