Advertisement
Guest User

Gun

a guest
Jan 21st, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.72 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Gun : MonoBehaviour
  6. {
  7.     public Transform barrel;
  8.     public float range = 0f;
  9.  
  10.     void Update ()
  11.     {
  12.         if (Input.GetButton("Fire1"))
  13.         {
  14.             Debug.Log("1");
  15.             StartCoroutine("Fire");
  16.         }
  17.     }
  18.  
  19.     IEnumerator Fire ()
  20.     {
  21.         Debug.Log("2");
  22.         RaycastHit hit;
  23.         Ray ray = new Ray(barrel.position, transform.forward);
  24.         if (Physics.Raycast(ray, out hit, range))
  25.         {
  26.             //if (hit.collider.tag == "Enemy")
  27.             //{
  28.             //  Enemy enemy = hit.collider.GetComponent<Enemy>();
  29.             //  enemy.health -= 1;
  30.             //}
  31.             Debug.Log("3");
  32.         }
  33.         Debug.DrawRay(barrel.position, transform.forward * range, Color.green);
  34.         yield return null;
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement