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!