Advertisement
AndrewRosyaev

PlayerShooting.cs

Nov 24th, 2015
683
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.Networking;
  4.  
  5. public class PlayerShooting : NetworkBehaviour {
  6.  
  7.     public int Damage = 25;
  8.     public Camera cameraTR;
  9.     private RaycastHit hit;
  10.     private Ray ray;
  11.  
  12.     void Update ()
  13.     {
  14.         if (Input.GetKeyDown (KeyCode.Mouse0))
  15.         {
  16.             Shoot();
  17.         }
  18.     }
  19.     void Shoot()
  20.     {
  21.         ray = cameraTR.ScreenPointToRay (Input.mousePosition);
  22.         if (Physics.Raycast (ray, out hit, 1000))
  23.         {
  24.             if(hit.transform.tag == "Player")
  25.             {
  26.                 string id = hit.transform.name;
  27.                 CmdShoot(id, Damage);
  28.             }
  29.         }
  30.     }
  31.     [Command]
  32.     void CmdShoot(string Id, int dmg)
  33.     {
  34.         GameObject go = GameObject.Find (Id);
  35.         go.GetComponent<PlayerInfo> ().GetDamage (dmg);
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement