Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Gun : MonoBehaviour {
- public float FireRate;
- public float MinDamage;
- public float MaxDamage;
- private float ActualDamage;
- private float FireTime;
- public float Range = 800;
- public Transform SpawnPoint;
- public string Name;
- public GameObject ImpactEffect;
- public Transform AimObj;
- public List<Sight> Sights = new List<Sight>();
- public int CurSight;
- public LayerMask hitlayers;
- public int UnlockLevel;
- public bool Unlocked;
- public int Kills;
- public bool Bought;
- public int Cost;
- // Use this for initialization
- void Start () {
- }
- // Update is called once per frame
- void Update () {
- if (Input.GetButtonDown ("Fire1"))
- Fire();
- foreach (Sight s in Sights)
- {
- if(Sights.IndexOf(s) == CurSight)
- {
- s.Obj.SetActive(true);
- }
- else
- {
- s.Obj.SetActive(false);
- }
- }
- }
- public void Fire()
- {
- if (FireTime <= Time.time)
- {
- FireTime = FireRate + Time.time;
- ActualDamage = Random.Range (MinDamage,MaxDamage);
- audio.Play ();
- NetworkManager.Instance.MyPlayer.Manager.Client_DoSound(Name);
- Debug.Log ("Fired");
- RaycastHit hit;
- if(Physics.Raycast (SpawnPoint.position,SpawnPoint.forward,out hit,Range)){
- if (hit.collider.rigidbody && hit.collider.GetComponent<PublicLocal>())
- {
- //hit.collider.rigidbody.AddForceAtPosition ((ActualDamage * 200) * transform.forward, hit.collider.transform.position);
- hit.collider.GetComponent<PublicLocal>().AddForceAddPosition_Network((ActualDamage * 200) * transform.forward,hit.collider.transform.position);
- }
- Character hitter = hit.transform.root.GetComponent<Character>();
- Network.Instantiate(ImpactEffect,hit.point,Quaternion.FromToRotation(hit.normal,Vector3.up),0);
- if (hitter != null)
- {
- hitter.networkView.RPC ("Server_TakeDamage",RPCMode.All,ActualDamage);
- hitter.networkView.RPC ("FindHitter",RPCMode.All , NetworkManager.Instance.MyPlayer.PlayerName,Name);
- }
- }
- }
- }
- void FixedUpdate()
- {
- if (Input.GetButton ("Fire2"))
- {
- AimObj.transform.localPosition = Vector3.Lerp(AimObj.transform.localPosition,Sights[CurSight].AimPos , 0.25f);
- }
- else
- {
- AimObj.transform.localPosition = Vector3.Lerp(AimObj.transform.localPosition,Vector3.zero, 0.25f);
- }
- }
- }
- [System.Serializable]
- public class Sight
- {
- public string Name;
- public GameObject Obj;
- public Vector3 AimPos;
- public int UnlockKills;
- public bool Unlocked;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement