Hack Forums
[C#] Unity 5.2 basic name and title system, - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] Unity 5.2 basic name and title system, (/showthread.php?tid=5194406)



Unity 5.2 basic name and title system, - Coffee is love - Mar 6, 2016

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.
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!


* - Oliver Sykes - Mar 6, 2016

So...did you solve it? Seems so from the edit.


* - Coffee is love - Mar 6, 2016

Yeah I'm having so many issues though cause last time I attempted to make this game it was the older unity


* - Carlsson94 - Mar 8, 2016

You should try to post it on Stackover Flow or back at the unity forums, I believe you can get more help there.


* - Coffee is love - Mar 8, 2016

yeah I did post it in those two places ;p people keep giving me old editions they probably cracked their version or something rather then staying with the updated client ;/ keep giving me stuff that doesn't exist anymore lol