Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace Project
- {
- public class EnemyShoot : MonoBehaviour
- {
- public float enemyDamage = 1f;
- public float enemyRange = 2f;
- public float shotDelay = 0.2f; //Delay of firing
- public float targetStart = 2f; //The time it takes inbetween targetting
- public float targetEnd = 0f; //Used for the loop below VVVV
- Transform player;
- Vector3 raycastDirection;
- // Use this for initialization
- void Start()
- {
- player = GameObject.FindGameObjectWithTag("Player").transform;
- }
- // Update is called once per frame
- // Update loop will have issues in it
- void Update()
- {
- if (!GUIManager.game_stop && GUIManager.gameStart)
- {
- targetStart -= Time.deltaTime;
- if (targetStart <= targetEnd) //Should cycle every 2 seconds
- {
- shotDelay -= Time.deltaTime;
- targetStart = 2f;
- Target();
- if (shotDelay <= 0f)
- {
- shotDelay = 0.2f;
- Shoot();
- }
- }
- }
- }
- // This is what I am using to Target, so that if the player stands still for too long, they are shot.
- void Target()
- {
- RaycastHit hit;
- Debug.Log("Target");
- raycastDirection = player.transform.position;
- if (Physics.Raycast(gameObject.transform.position, raycastDirection, out hit, enemyRange))
- {
- Debug.DrawLine(gameObject.transform.position, player.transform.position, Color.green, 10f);
- }
- }
- //This is the actual shot itself, it should be delayed by a certain amount after the player has been targeted.
- void Shoot()
- {
- Debug.Log("Shoot");
- if (player.tag == "Player")
- {
- Debug.Log("Get hit");
- Player.TakeDamage(enemyDamage);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement