Having trouble with spawning particles through rpc

Options

I am attempting to make the particle effects from my projectile visible to both players in my game. I currently have my OnCollsionEnter method on my projectile script, which is the code for moving the projectile. I decided using an RPC would be the best way to go. I do not want to have a photonview script on my projectiles, so I created a detection script (DestroyBullet) on my player that will detect when the projectile collider collides with the ground of my planet and other players in the future. But unfortunately, my code for that is not detecting the projectile or ground colliders and I do not know if this is even the best route for having particles visible on both players' screens.


on projectiles

Projectile Code:

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Projectile : MonoBehaviour
  6. {
  7.    public float bulletSpeed;
  8.    public GameObject pivotObject;
  9.    public GameObject player;
  10.   Vector3 perpendicular;
  11.   Vector3 distance;
  12.   
  13.  
  14.    // Start is called before the first frame update
  15.    void Start()
  16.    {
  17.     distance = (pivotObject.transform.position - player.transform.position).normalized;
  18.      var forward = player.transform.forward;
  19.     perpendicular = Vector3.Cross(distance, forward).normalized;
  20.    }
  21.  
  22.    // Update is called once per frame
  23.    void Update()
  24.    {
  25.     ProjectileMove();
  26.    }
  27.  
  28.    void LateUpdate()
  29.    {
  30.     transform.position = Vector3.MoveTowards(transform.position, pivotObject.transform.position, Time.deltaTime * 0.6f);
  31.    }
  32.  
  33.    void ProjectileMove()
  34.    {
  35.     transform.RotateAround(perpendicular, transform.up, bulletSpeed * Time.deltaTime);
  36.    }
  37.  
  38.    /*public Transform hitgroundPrefab;
  39.   public Transform hitwaterPrefab;
  40.   public GameObject decalPrefab;
  41.   private void OnCollisionEnter(Collision collision)
  42.   {
  43.     ContactPoint contact = collision.contacts[0];
  44.  
  45.     // Rotate the object so that the y-axis faces along the normal of the surface
  46.     Quaternion rot = Quaternion.FromToRotation(Vector3.up, contact.normal);
  47.     Vector3 pos = contact.point;
  48.  
  49.     if(collision.gameObject.layer == 3)
  50.     {
  51.       Instantiate(hitgroundPrefab, pos, rot);
  52.       Instantiate(decalPrefab, pos, rot);
  53.  
  54.       Destroy(gameObject);
  55.     }
  56.     
  57.     if(collision.gameObject.layer == 4)
  58.     {
  59.       Instantiate(hitwaterPrefab, pos, rot);
  60.  
  61.       Destroy(gameObject);
  62.     }
  63.   }*/
  64. }

DestroyBullet script on the player:

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using Photon.Pun;
  4. using UnityEngine;
  5.  
  6. public class DestroyBullet : MonoBehaviourPun
  7. {  
  8.    // Start is called before the first frame update
  9.    void Start()
  10.    {
  11.     
  12.    }
  13.  
  14.    // Update is called once per frame
  15.    void Update()
  16.    {
  17.     
  18.    }
  19.  
  20.    public Transform hitgroundPrefab;
  21.    public Transform hitwaterPrefab;
  22.    public GameObject decalPrefab;
  23.    [PunRPC] public void OnCollisionEnter(Collision collision)
  24.    {
  25.     ContactPoint contact = collision.contacts[0];
  26.  
  27.      // Rotate the object so that the y-axis faces along the normal of the surface
  28.     Quaternion rot = Quaternion.FromToRotation(Vector3.up, contact.normal);
  29.     Vector3 pos = contact.point;
  30.  
  31.      if(photonView.IsMine)
  32.      {
  33.       photonView.RPC("OnCollisionEnter", RpcTarget.All, collision);
  34.      }
  35.  
  36.      if(collision.gameObject.tag == "bullet" && collision.gameObject.layer == 3)
  37.        {
  38.         Instantiate(hitgroundPrefab, pos, rot);
  39.         Instantiate(decalPrefab, pos, rot);
  40.  
  41.         Destroy(gameObject);
  42.        }
  43.        else if(collision.gameObject.tag == "bullet" && collision.gameObject.layer == 4)
  44.        {
  45.         Instantiate(hitwaterPrefab, pos, rot);
  46.  
  47.         Destroy(gameObject);
  48.        }
  49.    }
  50. }