- Home /
 
 
               Question by 
               minecrafter2020 · Mar 06 at 04:22 PM · 
                c#photonpun  
              
 
              How to make rapid fire with photon unity networking?
Hello i need script for rapid fire with pun. I am making FPS multiplayer game I really need this script. Can someone help?
Here is script for normal shooting:
 [SerializeField] Camera cam;
 PhotonView PV;
 void Awake()
 {
     PV = GetComponent<PhotonView>();
 }
 public override void Use()
 {
     Shoot();
 }
 void Shoot()
 {
     Ray ray = cam.ViewportPointToRay(new Vector3(0.5f, 0.5f));
     ray.origin = cam.transform.position;
     if(Physics.Raycast(ray, out RaycastHit hit))
     {
         hit.collider.gameObject.GetComponent<IDamageable>()?.TakeDamage(((GunInfo)ItemInfo).damage);
         PV.RPC("RPC_Shoot",RpcTarget.All, hit.point, hit.normal);
     }
 }
 [PunRPC]
 void RPC_Shoot(Vector3 hitPosition, Vector3 hitNormal)
 {
     Collider[] colliders = Physics.OverlapSphere(hitPosition, 0.3f);
     if(colliders.Length != 0)
     {
         GameObject bulletImpactObj = Instantiate(bulletImpactPrefab, hitPosition + hitNormal * 0.001f, Quaternion.LookRotation(hitNormal, Vector3.up) * bulletImpactPrefab.transform.rotation);
         Destroy(bulletImpactObj, 10f);
         bulletImpactObj.transform.SetParent(colliders[0].transform);
     }
 }
 
               
               Comment
              
 
               
              using Photon.Pun; using System.Collections; using System.Collections.Generic; using UnityEngine;
public class SingleShotGun : Gun
rest of the code. and Gun scripts: using System.Collections; using System.Collections.Generic; using UnityEngine;
public abstract class Gun : Item { public abstract override void Use();
 public GameObject bulletImpactPrefab;
 
                  }
And Item: using System.Collections; using System.Collections.Generic; using UnityEngine;
public abstract class Item : MonoBehaviour { public ItemInfo ItemInfo; public GameObject itemGameObject;
 public abstract void Use();
 
                  }
Your answer