Mar 6, 2016 12:40 PM
(This post was last modified: Mar 6, 2016 01:01 PM by Coffee is love.)
Okay so what I have here is the code i am currently using, what happens is when i attach it to the two different objects, aka the player and an empty attached to him, it just says the players name anyway in two different spots, i'm not much of a coding professional so i don't know where i went wrong.
Update: I put root.name; on accident for the second one ;p so it automatically went up the hierarchy to the character name ;p I just got rid of root and presto!
Code
using UnityEngine;
using System.Collections;
public class DisplayNames : MonoBehaviour {
public Transform teleport;
public Transform player;
void Start () {
GetComponent<TextMesh>().text = transform.root.name;
GetComponent<TextMesh>().text = transform.root.name;
GetPlayer ();
}
void GetPlayer ()
{
GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
foreach (GameObject p in players)
{
if(p.GetComponent<NetworkView>().isMine)
{
player = p.transform;
}
}
}
void Update ()
{
if(player)
{
Vector3 lookPos = 2 * transform.position - player.position;
lookPos.y = player.position.y;
transform.LookAt (lookPos);
}
else
{
GetPlayer ();
}
}
}Update: I put root.name; on accident for the second one ;p so it automatically went up the hierarchy to the character name ;p I just got rid of root and presto!


