Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

Unity 5.2 basic name and title system,

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!
So...did you solve it? Seems so from the edit.

riperino animefanerino
(Sep 12, 2016 04:11 PM){Nexus} Wrote:  If the FBI come knocking I'm gonna spew information out my ass about Aeon.

They'd have to tell me to stop giving them information.

Yeah I'm having so many issues though cause last time I attempted to make this game it was the older unity
You should try to post it on Stackover Flow or back at the unity forums, I believe you can get more help there.
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


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by Lexxi.Dec 8, 2016 02:17 AM 3 195 Dec 8, 2016 02:17 AM
Last Post: Dеvil
[C#] by severosNov 18, 2016 02:11 AM 6 236 Nov 18, 2016 02:11 AM
Last Post: clrlslwi
[C#] by ChickendipperOct 1, 2016 07:14 AM 3 195 Oct 1, 2016 07:14 AM
Last Post: waxokrix