Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Photon.Pun;
- using UnityEngine.UI;
- public class FPSShoot : MonoBehaviourPun
- {
- PhotonView pv;
- public float PlayerDamage = 25f;
- public float TotalLife = 100f;
- public Camera cam;
- public LayerMask mask;
- public Image BarLife;
- void Start()
- {
- pv = GetComponent<PhotonView>();
- if (pv.IsMine)
- {
- cam.enabled = true;
- }
- else
- {
- cam.enabled = false;
- }
- }
- void Update()
- {
- if (pv.IsMine) {
- this.gameObject.tag = "Player";
- this.gameObject.layer = 3;
- BarLife.enabled = true;
- if (Input.GetKeyDown(KeyCode.Mouse0))
- {
- //Shoot();
- //Invoke ("Shoot", 1f);
- pv.RPC ("Shoot", RpcTarget.All);
- }
- BarLife.fillAmount = TotalLife / 100f;
- }
- else
- {
- BarLife.enabled = false;
- this.gameObject.tag = "Enemigo";
- this.gameObject.layer = 6;
- }
- if (TotalLife <= 1f)
- {
- if (pv.IsMine)
- {
- PhotonNetwork.Disconnect();
- }
- }
- }
- [PunRPC]
- public void Shoot()
- {
- RaycastHit hit;
- if (Physics.Raycast (cam.transform.position, cam.transform.forward, out hit, 100f, mask))
- {
- if (hit.transform.gameObject.layer != 6)
- {
- PhotonNetwork.Instantiate("Impact_FX", hit.point, Quaternion.LookRotation(hit.point));
- }
- else
- {
- PhotonNetwork.Instantiate("Blood_FX", hit.point, Quaternion.LookRotation(hit.point));
- hit.transform.GetComponent <PhotonView>().RPC ("damage", RpcTarget.All);
- }
- }
- }
- [PunRPC]
- public void damage()
- {
- TotalLife -= PlayerDamage;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement