Advertisement
Guest User

Strzelanie.cs

a guest
Aug 21st, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.91 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Networking;
  5. using UnityEngine.UI;
  6.  
  7. [RequireComponent(typeof(AudioSource))]
  8. public class Strzelanie : NetworkBehaviour {
  9.  
  10.     public ParticleSystem muzzle;
  11.     public RaycastHit hit;
  12.     public Transform Kamera;
  13.     public AudioClip shoot;
  14.     public AudioSource src;
  15.     public int ammoAll =500;
  16.     public int ammoMag = 100;
  17.      int ammoLoaded =100;
  18.     int ammoNeeded;
  19.     public Text amunicja;
  20.     int hp =100;
  21.     Strzelanie sc;
  22.  
  23.     // Use this for initialization
  24.     void Start ()
  25.     {
  26.  
  27.         ammoMag = 100;
  28.         ammoLoaded = 100;
  29.         ammoAll = 500;
  30.         amunicja.text = +ammoLoaded + "/" + ammoAll;
  31.     }
  32.  
  33.    
  34.        
  35.    
  36.  
  37.     // Update is called once per frame
  38.     void Update () {
  39.  
  40.         if (!isLocalPlayer)
  41.         {
  42.             return;
  43.         }
  44.  
  45.         ammoNeeded = ammoMag - ammoLoaded;
  46.  
  47.         amunicja.text= +ammoLoaded +"/" + ammoAll;
  48.  
  49.         if (Input.GetMouseButton(0) && isLocalPlayer && ammoLoaded>0)
  50.         {          
  51.             muzzle.Play(true);
  52.             src.PlayScheduled(10);
  53.             ammoLoaded = ammoLoaded-1;
  54.  
  55.             if (Physics.Raycast(Kamera.position, Kamera.forward, out hit , 3000))
  56.             {
  57.                 if(hit.collider.gameObject.tag=="Player")
  58.                 {
  59.                    sc =  hit.collider.GetComponent<Strzelanie>();
  60.                     sc.hp = sc.hp - 10;
  61.  
  62.                        
  63.                 }
  64.             }
  65.            
  66.         }
  67.  
  68.         if(Input.GetKeyDown(KeyCode.R) && isLocalPlayer && ammoAll>0)
  69.         {
  70.             gameObject.GetComponent<Animation>().Play("reload");
  71.             ammoLoaded = ammoLoaded + ammoNeeded;
  72.             ammoAll = ammoAll - ammoNeeded;          
  73.        }
  74.  
  75.         if(hp==0 && isLocalPlayer)
  76.         {
  77.             Debug.Log("Die");
  78.  
  79.         }
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement