Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Gun : MonoBehaviour
- {
- public Transform barrel;
- public float range = 0f;
- void Update ()
- {
- if (Input.GetButton("Fire1"))
- {
- Debug.Log("1");
- StartCoroutine("Fire");
- }
- }
- IEnumerator Fire ()
- {
- Debug.Log("2");
- RaycastHit hit;
- Ray ray = new Ray(barrel.position, transform.forward);
- if (Physics.Raycast(ray, out hit, range))
- {
- //if (hit.collider.tag == "Enemy")
- //{
- // Enemy enemy = hit.collider.GetComponent<Enemy>();
- // enemy.health -= 1;
- //}
- Debug.Log("3");
- }
- Debug.DrawRay(barrel.position, transform.forward * range, Color.green);
- yield return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement