using Photon.Pun;
using UnityEngine;

namespace PhotonTutorial.Weapons
    public class Weapon : MonoBehaviourPun
        //this will store how fast the bullet moves
        [SerializeField] private float projectileSpeed = 5f;
        //this will store the projectile that is going to be shooted from the gun
        [SerializeField] private GameObject projectile = null;
        //this will store where the bullets will spawn
        [SerializeField] private Transform spawnPoint = null;

        private void Update()
            //if this is my photon view (if this is my character and not any other players character) call the function that thakes input
            if (photonView.IsMine)
                //call the function that handles the input

        private void TakeInput()
            //if the player hasnt clicked mouse button, leave this function
            if(!Input.GetMouseButtonDown(0)) { return; }
            //since the user clicked the shooting button, call the function fire projectile, that is going to spawn a bullet on every player pc

        private void FireProjectile()
            //this is going to spawn the bullet on every computer (since we are using PunRPC)
            GameObject projectileInstance = PhotonNetwork.Instantiate(, spawnPoint.position, spawnPoint.rotation);
            //this is going to add velocity to where the spawn bullet is facing, in this case is from the spawn point
            projectileInstance.GetComponent<Rigidbody>().velocity = projectileInstance.transform.forward * projectileSpeed;
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter