Teleporting in Multiplayer?

Hey!

ive made a functional multiplayer sandbox game and wanted to add teleporting so I tried this script:

using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
using UnityEngine.UI;

public class TP : MonoBehaviour {

    //Our name
    public string playername;
    //Who we want to teleport to's name
    public string tpto;
    //our textbox and teleport button
    public GameObject textbox , button1;

    // Use this for initialization
    void Start () {
        textbox = GameObject.Find ("inputtp");
        button1 = GameObject.Find ("teleportbutton");

        textbox.SetActive (false);
        button1.SetActive (false);
    }
   
    // Update is called once per frame
    void Update () {
   
    }

    public void tpplayer(){
        //get who we actually want to teleport to
        tpto = GameObject.Find ("inputtp").GetComponent<InputField>().text;
        //if the player wishes to go to spawn
        if (tpto == "spawn") {
            //tp's player
            GameObject.Find (playername).transform.position = new Vector3 (0, 200, 0);
        } else {
            //else tp to the name

            //set our position to theirs (this is the part that dosent work!!)
            GameObject.Find (playername).transform.position = GameObject.Find (tpto).transform.position;
            //some debuging
            print (gameObject.transform.position.ToString());

        }
        }




    //Not to worry about just some UI stuff!

    public void tpon(){
       
        textbox.SetActive (true);
        button1.SetActive (true);
    }

    public void tpoff(){
        textbox.SetActive (false);
        button1.SetActive (false);
    }
}

the teleporting to a vector 3 position works but not teleporting to another object I have commented the code for you please help thank you!

You can just do seomthign like this :

tpto =GameObject.Find("inputtp").GetComponent<InputField>().text;
var comps = tpto.Split(new char[]{','' '}, SplitStringOptions.RemoveEmptyEntries );
var newPos = new Vector3( float.Parse( comps[0] ), float.Parse( comps[1] ), float.Parse( comps[2] ) );
 
GameObject.Find(playername).transform.position = newPos;

that way you can inut the position where you want to move the player instead of the name of the other object.

thank you I will add this and show where (co ordinates) the player is! thank you!

1 problem @crispybeans this line:

varcomps=tpto.Split(newchar[ ]{‘,’‘’},SplitStringOptions.RemoveEmptyEntries);

is messing everything up unexpected symbol " ’ " and splitstringoptions is not in current context

we need another way StringSplitOptions.RemoveEmptyEntries - Unknown identifier - Questions & Answers - Unity Discussions

publicvoidtpplayer(){
//getwhoweactuallywanttoteleport to
tpto=GameObject.Find(“inputtp”).GetComponent().text;

stringstringToSplit=“”;
char[ ]splitters={‘’};
string[ ]newPos1=tpto.Split(splitters, System.StringSplitOptions.RemoveEmptyEntries);
varnewPos=newVector3(float.Parse(newPos1[0]),float.Parse(newPos1[1]),float.Parse(newPos1[2]));
print(newPos.ToString());

GameObject.Find(playername).transform.position=newPos;

}
thank you for the help!