Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var TheDamage : int;
- var hitParticle : Transform;
- var Gun : GameObject;
- var AnimationName : String;
- //~~~~
- var CurrentAmmo : int;
- var Magazines : int;
- var MaxAmmo : int;
- var MaxMagazines : int;
- var CanShoot = true;
- var ReloadAnimationName : String;
- var style : GUIStyle;
- function Start () {
- }
- function Update () {
- if(CurrentAmmo <= 0 && Magazines >0){
- CanShoot = false;
- CurrentAmmo = MaxAmmo;
- Reload();
- }
- if(Input.GetButton("Fire1") && CurrentAmmo > 0 && CanShoot){
- networkView.RPC("Shoot", RPCMode.All);
- Gun.animation.Play(AnimationName);
- CurrentAmmo -= 1;
- }
- }
- @RPC
- function Shoot() {
- if(networkView.isMine){
- var hit : RaycastHit;
- var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5,Screen.height*0.5,0));
- if(Physics.Raycast (ray, hit, 100)){
- var particleClone = Network.Instantiate(hitParticle, hit.point, Quaternion.LookRotation(hit.normal), 0);
- Destroy(particleClone.gameObject, 0.5);
- if(hit.transform.tag == "Player"){
- hit.transform.networkView.RPC("ApplyDamage", RPCMode.All, TheDamage);
- }
- }
- }
- }
- function Reload() {
- GetComponentInChildren(Recoil).enabled = false;
- Gun.animation.Play(ReloadAnimationName);
- Magazines -= 1;
- yield WaitForSeconds(2);
- CanShoot = true;
- GetComponentInChildren(Recoil).enabled = true;
- }
- function OnGUI() {
- GUILayout.Label("Ammo: "+CurrentAmmo+"/"+Magazines,style);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement