Search Unity

Networked linerenderer not visible on other players

Discussion in 'Multiplayer' started by Bender_R, Jul 9, 2020.

  1. Bender_R

    Bender_R

    Joined:
    May 21, 2018
    Posts:
    115
    Hi there,

    I have the feeling that I'm missing something very basic. With I can't find out what is wrong.

    I have this script that shoots a simple beam (linerenderer). I want this beam to be visible on other player also. But it isn't. RPC call is firing well, but line is only visible on firing client.

    Any hints?

    Code (CSharp):
    1. public class FireBeam : MonoBehaviour
    2. {
    3.     LineRenderer lr;
    4.     PhotonView PV;
    5.  
    6.         // Start is called before the first frame update
    7.     void Start()
    8.     {
    9.         lr = GetComponent<LineRenderer>();
    10.         lr.enabled = false;
    11.  
    12.         PV = GetComponent<PhotonView>();
    13.     }
    14.  
    15.     // Update is called once per frame
    16.     void Update()
    17.     {
    18.         if (Input.GetKey(KeyCode.Space) && PV.IsMine)
    19.         {
    20.             PV.RPC("RPC_Beam", RpcTarget.All, this.transform.position, new Vector3(this.transform.position.x, this.transform.position.y + 5));
    21.         }
    22.         else
    23.         {
    24.             lr.enabled = false;
    25.         }
    26.     }
    27.  
    28.     [PunRPC]
    29.     public void RPC_Beam(Vector3 start, Vector3 end)
    30.     {
    31.         lr.enabled = true;
    32.         lr.SetPosition(0, start);
    33.         lr.SetPosition(1, end);
    34.         Debug.Log("Beam!! " + start + " | " + end);
    35.     }
     
  2. cpasjuste

    cpasjuste

    Joined:
    Apr 2, 2012
    Posts:
    154
    Hi,

    You probably already figured it out but in update you are constantly disabling the line for other players, I guess your problem comes from here.
     
  3. Bender_R

    Bender_R

    Joined:
    May 21, 2018
    Posts:
    115
    Omg... :confused: Sorry for wasting a page on the internet, if this is the issue... which it probably is.. Thanks!!
     
  4. rayman600

    rayman600

    Joined:
    Nov 12, 2017
    Posts:
    12
    Just a tip for anyone looking at this in 2023. Make sure you have a PhotonView on your object that has this script attached to it.