player name tags not always facing camera of every client (PhotonNetwork)
hey guys i tried to get this working but no luck i am using photon network and i wanted all my other players name tags to face me in my client and with the other players the other way arround so my UIText will face them in their client i did post a simular post befour but didnt think it was clear what i wanted i have this script on the canvas that is above the characters /players is thare a way of doing this ?.. also i put in the if statement so when thare are no players accept me it wil not bug and if i have only my client no bug but as soon as i startup an other client it say refference not set to an instance of an object becouse it can`t find a main camera here is the script
public class BilBord_Face_Camera : MonoBehaviour
{
private Transform mainCameraTransform;
private void Start()
{
mainCameraTransform = Camera.main.transform;
}
private void LateUpdate()
{
if(mainCameraTransform == null)
{
}
else
{
transform.LookAt(transform.position + mainCameraTransform.rotation * Vector3.forward,
mainCameraTransform.rotation * Vector3.up);
}
}
}
Answer by madhavarora · Jan 28 at 05:23 PM
Having the same problem. Were you able to solve it? @Wesley21spelde
actualy yes are you using Photon unity Networking? my solution was to make a if photonview is $$anonymous$$e like this.. ill share my code... ................................................................................................................................ using System.Collections; using UnityEngine.UI; using UnityEngine;
public class Player_Name_Tag : Photon.MonoBehaviour
{
public Text m_MyText;
public GameObject target;
public void Awake()
{
m_MyText.GetComponent<Text>().text = photonView.owner.NickName;
}
void Update()
{
if (photonView.isMine)
{
}
else
{
target = GameObject.FindWithTag("Player");
transform.parent.transform.LookAt(target.transform);
}
}
}
i will explaine how i did this to begin i am the only Player who`s tag is player. by default my player prefab is a tag player but i dont want everyone to be taged player only your self on your clienet so someone else should be also taged player but only at their end in their clienet i used for this a same method with the photonview is$$anonymous$$e so if it is do nothing and else so if i am on someone els`s clienet change my tag to enemy. this way you are always the only one taged as player than i used the code above to say if photonview is $$anonymous$$e do nothing but if you are someone els look at me (player. you can also see i did a transform.parent becouse in my case my text was fliped and the code is on the text so i did the rotation on the parent and it fixed my text it is now looking at me the right way and not backwards. i hope it works for you too if you still have any questions ill help you where i can
Using mirror, although i did manage to get an extremely simple solution. Add a script to the text object
using UnityEngine;
public class NameFaceCamera : MonoBehaviour
{
void Update()
{
transform.LookAt(Camera.main.transform);
transform.Rotate(0, 180, 0);
}
}
This works because there is only one camera inside the scene. Scratched my head trying to solve this in the most complex way and then finally realised how simple it actually was.
yeah same here :D what kind of game are u making ?
Your answer
Follow this Question
Related Questions
Multiplayer Game Networking Layer Problem 0 Answers
[UNET/JS] How to enable local player controll 0 Answers
multiplayer game -how to connect each game-object to specific network player 0 Answers
Multiplayer 2 Answers
Multiplayer Camera Rotation On Client 0 Answers