Advertisement
jasonjohn

GUN

Jul 13th, 2014
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1.  
  2. public class Gun : MonoBehaviour {
  3. public float FireRate;
  4. public float MinDamage;
  5. public float MaxDamage;
  6. private float ActualDamage;
  7. private float FireTime;
  8. public float Range = 800;
  9. public Transform SpawnPoint;
  10. public string Name;
  11. public GameObject ImpactEffect;
  12. public Transform AimObj;
  13. public List<Sight> Sights = new List<Sight>();
  14. public int CurSight;
  15. public LayerMask hitlayers;
  16. public int UnlockLevel;
  17. public bool Unlocked;
  18. public int Kills;
  19. public bool Bought;
  20. public int Cost;
  21.  
  22. // Use this for initialization
  23. void Start () {
  24.  
  25. }
  26.  
  27. // Update is called once per frame
  28. void Update () {
  29. if (Input.GetButtonDown ("Fire1"))
  30. Fire();
  31.  
  32.  
  33. foreach (Sight s in Sights)
  34. {
  35. if(Sights.IndexOf(s) == CurSight)
  36. {
  37. s.Obj.SetActive(true);
  38. }
  39. else
  40. {
  41. s.Obj.SetActive(false);
  42. }
  43. }
  44. }
  45.  
  46. public void Fire()
  47. {
  48. if (FireTime <= Time.time)
  49. {
  50. FireTime = FireRate + Time.time;
  51. ActualDamage = Random.Range (MinDamage,MaxDamage);
  52. audio.Play ();
  53. NetworkManager.Instance.MyPlayer.Manager.Client_DoSound(Name);
  54. Debug.Log ("Fired");
  55. RaycastHit hit;
  56. if(Physics.Raycast (SpawnPoint.position,SpawnPoint.forward,out hit,Range)){
  57. if (hit.collider.rigidbody && hit.collider.GetComponent<PublicLocal>())
  58. {
  59. //hit.collider.rigidbody.AddForceAtPosition ((ActualDamage * 200) * transform.forward, hit.collider.transform.position);
  60.  
  61. hit.collider.GetComponent<PublicLocal>().AddForceAddPosition_Network((ActualDamage * 200) * transform.forward,hit.collider.transform.position);
  62. }
  63. Character hitter = hit.transform.root.GetComponent<Character>();
  64. Network.Instantiate(ImpactEffect,hit.point,Quaternion.FromToRotation(hit.normal,Vector3.up),0);
  65.  
  66. if (hitter != null)
  67. {
  68. hitter.networkView.RPC ("Server_TakeDamage",RPCMode.All,ActualDamage);
  69. hitter.networkView.RPC ("FindHitter",RPCMode.All , NetworkManager.Instance.MyPlayer.PlayerName,Name);
  70. }
  71. }
  72. }
  73. }
  74. void FixedUpdate()
  75. {
  76. if (Input.GetButton ("Fire2"))
  77. {
  78. AimObj.transform.localPosition = Vector3.Lerp(AimObj.transform.localPosition,Sights[CurSight].AimPos , 0.25f);
  79. }
  80. else
  81. {
  82. AimObj.transform.localPosition = Vector3.Lerp(AimObj.transform.localPosition,Vector3.zero, 0.25f);
  83. }
  84. }
  85. }
  86.  
  87. [System.Serializable]
  88. public class Sight
  89. {
  90. public string Name;
  91. public GameObject Obj;
  92. public Vector3 AimPos;
  93. public int UnlockKills;
  94. public bool Unlocked;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement