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*);*
}
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