Instantiating hitpoint debris/blood/fx with photon ?

Options
Hi,

This is my original code to instantiate an effect wherever my raycast hits and it works, but only on my players screen as it isn't sent over the network with photon. I've looked into PhotonNetwork.Instantiate but I can't get it to work as it has to happen on the "hitpoint" in real time:

Code (CSharp):
        Ray ray = new Ray(RootToShoot.transform.position, RootToShoot.transform.forward);
        Transform hitTransform;
        Vector3 hitPoint;

        hitTransform = FindClosestHitObject(ray, out hitPoint);
        if (hitTransform != null)
        {

        if (hitTransform.gameObject.tag == "rock")
 
            {
                GameObject impactGO = Instantiate(impactEffectrock, hitPoint, transform.rotation);
                Destroy(impactGO, 1f);
            }
The raycast, however, is visible over the network as I used [PunRPC] on this shooting function. I wonder how to instantiate the hitpoint effects over the network based on the code above. Can anyone help me with this? It would be very much appreciated.

Comments

  • jRocket
    Options
    I would not use PhotonNetwork.Instantiate because that is for instantiating networked objects. Instead, you can call an RPC when the shooting happens and each client can use the normal Object.Instantiate to create the effects.
  • petersenjmp
    Options
    jRocket said:

    I would not use PhotonNetwork.Instantiate because that is for instantiating networked objects. Instead, you can call an RPC when the shooting happens and each client can use the normal Object.Instantiate to create the effects.

    Okay but how do I instantiate the effect and call the RPC? I've tried the following with a photonView component on the "impactEffectwater" Game Object and I doesn't show on other players screens:

    PhotonView pvw = impactEffectwater.GetComponent();
    if (pvw == null)
    {
    Debug.LogError("Missing PhotonView script");
    }
    if (pvw != null)
    {
    impactEffectwater = Instantiate(impactEffectwater, hitPoint, transform.rotation);