Advertisement
Munchy2007

PlayerShoot_Full

Jan 10th, 2018
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. namespace PUNTutorial
  6. {
  7.     public class PlayerShoot : Photon.PunBehaviour
  8.     {
  9.         [SerializeField] Missile missilePefab;
  10.         float nextFireTime;
  11.         float fireDelay = 0.25f;
  12.  
  13.         void Awake()
  14.         {
  15.             enabled = photonView.isMine;
  16.         }
  17.  
  18.         void Update()
  19.         {
  20.             if (Time.time < nextFireTime) return;
  21.  
  22.             if (Input.GetAxis("Fire1") > 0)
  23.             {
  24.                 nextFireTime = Time.time + fireDelay;
  25.                 photonView.RPC("RPC_FireMissile", PhotonTargets.All);
  26.             }
  27.         }
  28.  
  29.         [PunRPC]
  30.         void RPC_FireMissile(PhotonMessageInfo info)
  31.         {
  32.             var missile = Instantiate(missilePefab, transform.position, transform.rotation);
  33.             missile.SetOwner(info.photonView);
  34.             missile.gameObject.SetActive(true);
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement