Raphafrei

Bullet

Nov 28th, 2017
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Bullet : MonoBehaviour {
  5.  
  6.     public float speed;
  7.  
  8.     public int damage = 50;
  9.     public int headDamage = 100;
  10.  
  11.     public GameObject bloodEffect;
  12.     public GameObject bulletHole;
  13.  
  14.     float maxDist = 1000000000;
  15.  
  16.     void Start () {
  17.  
  18.     }
  19.  
  20.  
  21.     void Update() {
  22.         transform.Translate(Vector3.forward * speed * Time.deltaTime);
  23.  
  24.         RaycastHit hit;
  25.         if (Physics.Raycast(transform.position, transform.forward, out hit, maxDist)) {
  26.             if (bulletHole && hit.transform.tag != "Zombie")
  27.                 Instantiate(bulletHole, hit.point + (hit.normal * 0.00001f), Quaternion.LookRotation(hit.normal * -1));
  28.             if (hit.transform.tag == "Zombie") {
  29.                 hit.transform.gameObject.BroadcastMessage("ApplyDamage", damage);
  30.                 Instantiate(bloodEffect, transform.position, transform.rotation);
  31.             }
  32.                 Destroy(this.gameObject);
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment