Guest User

Untitled

a guest
Jan 20th, 2016
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1. public int damagePerShot = 10; // The damage inflicted by each bullet.
  2. public float timeBetweenAttacks = 0.15f; // The time between each shot.
  3. public float range = 2f; // The distance the gun can fire.
  4.  
  5. float timer; // A timer to determine when to fire.
  6. Ray shootRay; // A ray from the gun end forwards.
  7. RaycastHit shootHit; // A raycast hit to get information about what was hit.
  8. int shootableMask; // A layer mask so the raycast only hits things on the shootable layer.
  9. ParticleSystem gunParticles; // Reference to the particle system.
  10. LineRenderer gunLine; // Reference to the line renderer.
  11. //AudioSource gunAudio; // Reference to the audio source.
  12. Light gunLight; // Reference to the light component.
  13. float effectsDisplayTime = 1f; // The proportion of the timeBetweenBullets that the effects will display for.
  14.  
  15. void Awake()
  16. {
  17. // Create a layer mask for the Shootable layer.
  18. shootableMask = LayerMask.GetMask("Attackable");
  19.  
  20. // Set up the references.
  21. // gunParticles = GetComponent<ParticleSystem>();
  22. gunLine = GetComponent<LineRenderer>();
  23. // gunAudio = GetComponent<AudioSource>();
  24. // gunLight = GetComponent<Light>();
  25. }
  26.  
  27. void Update()
  28. {
  29. // Add the time since Update was last called to the timer.
  30. // timer += Time.deltaTime;
  31.  
  32. // If the Fire1 button is being press and it's time to fire...
  33. //if (Input.GetButton("Fire1") && timer >= timeBetweenBullets)
  34. // {
  35. // ... shoot the gun.
  36. // Shoot();
  37. // }
  38. //
  39. // If the timer has exceeded the proportion of timeBetweenBullets that the effects should be displayed for...
  40. // if (timer >= timeBetweenBullets * effectsDisplayTime)
  41. // {
  42. // ... disable the effects.
  43. // DisableEffects();
  44. /// }
  45. }
  46.  
  47. public void DisableEffects()
  48. {
  49. // Disable the line renderer and the light.
  50. gunLine.enabled = false;
  51. // gunLight.enabled = false;
  52. }
  53.  
  54. void Shoot()
  55. {
  56. // Reset the timer.
  57. // timer = 0f;
  58.  
  59. // Play the gun shot audioclip.
  60. // gunAudio.Play();
  61.  
  62. // Enable the light.
  63. // gunLight.enabled = true;
  64.  
  65. // Stop the particles from playing if they were, then start the particles.
  66. // gunParticles.Stop();
  67. // gunParticles.Play();
  68.  
  69. // Enable the line renderer and set it's first position to be the end of the gun.
  70. gunLine.enabled = true;
  71. gunLine.SetPosition(0, gameObject.transform.position);
  72.  
  73. // Set the shootRay so that it starts at the end of the gun and points forward from the barrel.
  74. Vector3 NewOrigin = new Vector3(transform.position.x,transform.position.y , transform.position.z);
  75. shootRay.origin = NewOrigin;
  76. shootRay.direction = transform.forward;
  77.  
  78. // Perform the raycast against gameobjects on the shootable layer and if it hits something...
  79. if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
  80. {
  81. // Try and find an EnemyHealth script on the gameobject hit.
  82. EnemyStats enemyHealth = shootHit.collider.GetComponent<EnemyStats>();
  83.  
  84.  
  85. if (enemyHealth != null)
  86. //print("should be damaging the enemy");
  87. enemyHealth.DamageEnemy(damagePerShot);
  88. }
  89.  
  90.  
  91.  
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment