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 Shoot : MonoBehaviour
- {
- public float shootRate;
- float currentDelay = 0f;
- public float damage = 20f;
- void Start()
- {
- }
- // Update is called once per frame
- void Update()
- {
- if (Input.GetMouseButtonDown(0))
- {
- if (currentDelay <= 0)
- {
- shoot();
- }
- }
- if (currentDelay > 0)
- {
- currentDelay -= Time.deltaTime;
- }
- }
- void shoot()
- {
- Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- RaycastHit hit;
- if (Physics.Raycast (ray, out hit, float.PositiveInfinity) )
- {
- GameObject obj = hit.collider.gameObject;
- Heal health = obj.GetComponent<Heal>();
- if(health)
- {
- health.DealDamage(damage);
- }
- }
- currentDelay = shootRate;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement