PUN Basics Tutorial: 9 - Player UI Prefab

1.

In the "Following the Target Player" section the next code

targetRenderer = this.target.GetComponent<Renderer>();

wouldn't work because Renderer is attached to a child element, not to the root. So, we have to write

targetRenderer = this.target.GetComponentInChildren<Renderer>();

--------------------------------
2.

In the same section the next code
void LateUpdate()
{
    // Do not show the UI if we are not visible to the camera, thus avoid potential bugs with seeing the UI, but not the player itself.
    if (targetRenderer != null)
    {
        this.gameObject.SetActive(targetRenderer.isVisible);
    }

    if (targetTransform != null)
    {
        targetPosition = targetTransform.position;
        targetPosition.y += characterControllerHeight;
        this.transform.position = Camera.main.WorldToScreenPoint(targetPosition) + screenOffset;
    }
}
wouldn't work too because once gameObject is set inactive the LateUpdate method wouldn't be called anymore (see MonoBehaviour.LateUpdate()).

Comments

  • Hi @develax,

    Thank you for your reports we will investigate!
  • @JohnTube sometimes when I try to connect 2 apps I get "OnJoinRandomFailed: No match found, returnCode = 32760", but other time it's ok. Maybe you know why this failure could happen?
  • Hi @develax,

    This is expected in the early stages of the development phase where you test using two clients.
    The server will receive the 2nd client's join random room request before finishing the creation of the room created by the first client. You should wait before starting the 2nd client or calling join random room.
  • develax
    develax
    edited June 2019
    Hi @JohnTube,
    in order not to create confusion, I have created a separate discussion for this issue.

  • Hi,

    Doing this isn't going to be enough, I am it, trying to find the best way to tackle this case.

    Bye,

    Jean
  • Hi @jeanfabre,
    if you mean hiding player UI, I think this should work:
    if (_targetRenderer.isVisible)
        transform.SetParent(_canvas.GetComponent<Transform>()); // Show UI.
    else
        transform.SetParent(null); // Hide UI.
  • Hi,

    I went for using CanvasGroup, which gives you more potential for animation, and a greater control, but yes, that should work too.

    Bye,

    Jean