Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Billboard nametag not working

Discussion in 'Editor & General Support' started by blabberbytes, Aug 6, 2020.

  1. blabberbytes

    blabberbytes

    Joined:
    Nov 22, 2014
    Posts:
    13
    So i'm using PUN2 and tryna do nametag billboard for my players but its not working for some reason. I think it has something to do with me destroying the camera on the player controller script. When I load the game the camera is destroyed for the players which has something to do with the phonoview. Im a noob and need some help. Thanks! This is the billboard scriot

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5.  
    6.     public class BillBoard : MonoBehaviour
    7.     {
    8.  
    9.  
    10.     private Transform mainCameraTransform;
    11.  
    12.       private void Start()
    13.       {
    14.           mainCameraTransform = mainCameraTransform.transform;
    15.       }
    16.  
    17.       private void LateUpdate()
    18.       {
    19.      
    20.         {
    21.               transform.LookAt(transform.position + mainCameraTransform.rotation * Vector3.forward,
    22.   mainCameraTransform.rotation * Vector3.up);
    23.           }
    24.  
    25.       }
    26.  
    27. }
    This is the player controller script:

    Code (CSharp):
    1.  
    2.  
    3. using Photon.Pun;
    4. using System.Collections;
    5. using System.Collections.Generic;
    6. using UnityEngine;
    7.  
    8. public class PlayerController : MonoBehaviour
    9. {
    10.     [SerializeField] GameObject cameraHolder;
    11.  
    12.     [SerializeField] float mouseSensitivity, sprintSpeed, walkSpeed, jumpForce, smoothTime;
    13.  
    14.     float verticalLookRotation;
    15.     bool grounded;
    16.     Vector3 smoothMoveVelocity;
    17.     Vector3 moveAmount;
    18.  
    19.     Rigidbody rb;
    20.  
    21.     PhotonView PV;
    22.  
    23.     void Awake()
    24.     {
    25.         rb = GetComponent<Rigidbody>();
    26.         PV = GetComponent<PhotonView>();
    27.     }
    28.  
    29.     void Start()
    30.     {
    31.         if (!PV.IsMine)
    32.         {
    33.             Destroy(GetComponentInChildren<Camera>().gameObject);
    34.             Destroy(rb);
    35.         }
    36.     }
    37.  
    38.     void Update()
    39.     {
    40.         if (!PV.IsMine)
    41.             return;
    42.  
    43.         Look();
    44.         Move();
    45.         Jump();
    46.     }
    47.  
    48.     void Look()
    49.     {
    50.         transform.Rotate(Vector3.up * Input.GetAxisRaw("Mouse X") * mouseSensitivity);
    51.  
    52.         verticalLookRotation += Input.GetAxisRaw("Mouse Y") * mouseSensitivity;
    53.         verticalLookRotation = Mathf.Clamp(verticalLookRotation, -90f, 90f);
    54.  
    55.         cameraHolder.transform.localEulerAngles = Vector3.left * verticalLookRotation;
    56.     }
    57.  
    58.     void Move()
    59.     {
    60.         Vector3 moveDir = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")).normalized;
    61.  
    62.         moveAmount = Vector3.SmoothDamp(moveAmount, moveDir * (Input.GetKey(KeyCode.LeftShift) ? sprintSpeed : walkSpeed), ref smoothMoveVelocity, smoothTime);
    63.     }
    64.  
    65.     void Jump()
    66.     {
    67.         if (Input.GetKeyDown(KeyCode.Space) && grounded)
    68.         {
    69.             rb.AddForce(transform.up * jumpForce);
    70.         }
    71.     }
    72.  
    73.     public void SetGroundState(bool _grounded)
    74.     {
    75.         grounded = _grounded;
    76.     }
    77.  
    78.     void FixedUpdate()
    79.     {
    80.         if (!PV.IsMine)
    81.             return;
    82.  
    83.         rb.MovePosition(rb.position + transform.TransformDirection(moveAmount) * Time.fixedDeltaTime);
    84.     }
    85. }
    86.  
     
    Last edited: Aug 6, 2020
    Ikee_0521 likes this.
  2. blabberbytes

    blabberbytes

    Joined:
    Nov 22, 2014
    Posts:
    13
  3. Ikee_0521

    Ikee_0521

    Joined:
    Jan 15, 2020
    Posts:
    4
    have you already solved this problem? we do have the same problem hope you can help me