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 killa247 · Sep 11, 2014 at 05:00 AM · 4.6chat

How to get player id's from owners name? Pun network

so what i have is an object in the scene that sets the name of the player (the player sets their name say "Bob") and i get a string and int from a code the player enters in the chat, eg "/speed, 20"

and then i need to set an object that the player controls to the owners name, how do i do this?

what i have so far : commands script-

 using UnityEngine;
 using System.Collections;
 
 public class Commands : Photon.MonoBehaviour {
     private float i = 0.0F;
     private string name;
     GameObject player;
     RigidbodyFPSController controllerScript;
     // Use this for initialization
     public void Command(string com){
                 Debug.Log (com);
                 string[] splitstring = com.Split (',');
                 if (splitstring.Length > 0){
                         Debug.Log (splitstring [1]);
         }
         i = float.Parse(splitstring [1]);
         if (splitstring[0] == "/speed" && i > 0 || i < 1000 ) {
             Debug.Log(name + "" + splitstring[0] + " " + i);
             //controllerScript = player.GetComponent<RigidbodyFPSController>();
             //controllerScript.speed = i;
                 }
         }
     public void Player(string PlayerUserName){
         name = PlayerUserName;
         //player = PhotonView.Find (PlayerUserName);
         }
 }


Chat code-

 using System.Collections.Generic;
 using UnityEngine;
 using System.Collections;
 
 [RequireComponent(typeof(PhotonView))]
 public class InRoomChat : Photon.MonoBehaviour 
 {
     public Rect GuiRect = new Rect(0,0, 250,300);
     public bool IsVisible = true;
     public bool AlignBottom = false;
     public List<string> messages = new List<string>();
     private string inputLine = "";
     private Vector2 scrollPos = Vector2.zero;
     public Commands com;
 
     public static readonly string ChatRPC = "Chat";
 
     public void Start()
     {    
         if (this.AlignBottom)
         {
             this.GuiRect.y = Screen.height - this.GuiRect.height;
         }
     }
 
     public void OnGUI()
     {
         com = GetComponent<Commands>();
         if (!this.IsVisible || PhotonNetwork.connectionStateDetailed != PeerState.Joined)
         {
             return;
         }
         
         if (Event.current.type == EventType.KeyDown && (Event.current.keyCode == KeyCode.KeypadEnter || Event.current.keyCode == KeyCode.Return))
         {
             if (!string.IsNullOrEmpty(this.inputLine))
             {
                 if (inputLine[0] == '/'){
                     com.Command(inputLine);
                     this.inputLine = "";
                     GUI.FocusControl("");
                     return;
                 }
                 else {
                 this.photonView.RPC("Chat", PhotonTargets.All, this.inputLine);
                 this.inputLine = "";
                 GUI.FocusControl("");
                 return; // printing the now modified list would result in an error. to avoid this, we just skip this single frame
                 }}
             else
             {
                 GUI.FocusControl("ChatInput");
             }
         }
 
         GUI.SetNextControlName("");
         GUILayout.BeginArea(this.GuiRect);
 
         scrollPos = GUILayout.BeginScrollView(scrollPos);
         GUILayout.FlexibleSpace();
         for (int i = messages.Count - 1; i >= 0; i--)
         {
             GUILayout.Label(messages[i]);
         }
         GUILayout.EndScrollView();
 
         GUILayout.BeginHorizontal();
         GUI.SetNextControlName("ChatInput");
         inputLine = GUILayout.TextField(inputLine);
         if (GUILayout.Button("Send", GUILayout.ExpandWidth(false)))
         {
             this.photonView.RPC("Chat", PhotonTargets.All, this.inputLine);
             this.inputLine = "";
             GUI.FocusControl("");
         }
         GUILayout.EndHorizontal();
         GUILayout.EndArea();
     }
 
     [RPC]
     public void Chat(string newLine, PhotonMessageInfo mi)
     {
         string senderName = "anonymous";
 
         if (mi != null && mi.sender != null)
         {
             if (!string.IsNullOrEmpty(mi.sender.name))
             {
                 senderName = mi.sender.name;
                 com.Player(mi.sender.name);
             }
             else
             {
                 senderName = "player " + mi.sender.ID;
             }
         }
 
         this.messages.Add(senderName +": " + newLine);
     }
 
     public void AddLine(string newLine)
     {
         this.messages.Add(newLine);
     }
 }


thanks in advance

Comment
Add comment · Show 3
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
avatar image Landern · Sep 11, 2014 at 05:04 AM 0
Share

Please format your code in the future, i've gone ahead and gone it for you, but please see the screens below, if unformatted... well it's a mess and you WILL get less responses from users.

Unformatted:

alt text

Formatted:

alt text

formatttedcode.png (48.6 kB)
unformatted.png (32.6 kB)
avatar image killa247 · Sep 11, 2014 at 05:14 AM 0
Share

i tried to add it into the code thing, but it wouldn't format it, the other script done it, was weird

avatar image Landern · Sep 11, 2014 at 05:53 AM 0
Share

@killa247, i find it easier to paste the code in, then highlight it in the textarea then click on the 101010 button, this seems to be more accurate then click 101010, pasting it in the popup and hitting ok

1 Reply

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by AlucardJay · Sep 11, 2014 at 05:38 AM

PhotonNetwork.playerName will return the name of the local player.

PhotonPlayer.name will also return the name of the local player.

PhotonNetwork.player.name will also return the name of the local player.

PhotonNetwork.player.ID will return the ID of the local player.

PhotonNetwork.player.isLocal will return if the player is the local player.

 Debug.Log ( PhotonNetwork.playerName + " : " + PhotonNetwork.player.name + " : " + PhotonNetwork.player.ID + " : " + PhotonNetwork.player.isLocal );


PhotonNetwork.player returns the class PhotonPlayer

http://doc-api.exitgames.com/en/realtime/current/pun/doc/class_photon_player.html

Comment
Add comment · Show 4 · Share
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
avatar image killa247 · Sep 11, 2014 at 05:49 AM 0
Share

but how do i set the object that the player is using to the one in game? i want to change the speed variable of the player he controls

avatar image AlucardJay · Sep 11, 2014 at 05:57 AM 1
Share
 if ( photonView.is$$anonymous$$ine )
     DoStuff();

or send a RPC.

Normally when I NetworkInstantiate an object, I store a reference to that object in my PlayerScript, so things like this are not a problem :

 GameObject playerObject = (GameObject)PhotonNetwork.Instantiate( "PlayerPrefab", startPos, startRot, 0 );
 ObjectController objectController = playerObject.GetComponent< ObjectController >();
 objectController.photonView.RPC( "SetName", PhotonTargets.AllBuffered, PhotonNetwork.playerName );
avatar image killa247 · Sep 11, 2014 at 06:02 AM 0
Share

is it possible to skype you? it could make this allot easier, and i would understand allot faster.

i dont have that right now when players are Instantiated

add me "Juane.gray" if you can please ^_^

avatar image killa247 · Sep 11, 2014 at 06:22 AM 0
Share

whoops i was being a tad retarded disregard that previous message, i just did the reference thing, way more obvious, thanks. :)

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

25 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

List of string is duplicated [C#] 1 Answer

PlayerName in Chat Window 2 Answers

Network.player giving me 0 0 Answers

Photon MMO chat 0 Answers

My Voice Chat Script Don't work 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