Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using UnityEngine.Networking;
- public class PlayerShooting : NetworkBehaviour {
- public int Damage = 25;
- public Camera cameraTR;
- private RaycastHit hit;
- private Ray ray;
- void Update ()
- {
- if (Input.GetKeyDown (KeyCode.Mouse0))
- {
- Shoot();
- }
- }
- void Shoot()
- {
- ray = cameraTR.ScreenPointToRay (Input.mousePosition);
- if (Physics.Raycast (ray, out hit, 1000))
- {
- if(hit.transform.tag == "Player")
- {
- string id = hit.transform.name;
- CmdShoot(id, Damage);
- }
- }
- }
- [Command]
- void CmdShoot(string Id, int dmg)
- {
- GameObject go = GameObject.Find (Id);
- go.GetComponent<PlayerInfo> ().GetDamage (dmg);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement