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 Proj_Tube : TorpedoSystem
- {
- public string Keycode;
- protected GuidedProj projScript;
- public GameObject torpedo_Target;
- RaycastHit2D hitObj;
- Vector2 raycastPos;
- public bool FiringAI;
- public bool canFire; //determines if the player can launch a salvo of torpedos
- public float t_Delay; //determines how long between each torpedo launched.
- public float cooldown; //determines how often you can launch torpedos
- public int torpedoAmt; //determines how many torpedos are spawned.
- int torpedoCount; //current number of torpedos spawned.
- // Start is called before the first frame update
- void Start()
- {
- canFire = true;
- }
- // Update is called once per frame
- void Update()
- {
- if (Input.GetKeyDown(Keycode) && base.isAI == false)
- {
- if (canFire == true)
- {
- FiringMethod();
- StartCoroutine(CDCheck());
- }
- }
- if (Input.GetMouseButton(0) && base.isAI == false)
- {
- AssignTarget();
- Debug.Log("Locked on:" + torpedo_Target);
- }
- AIFiring();
- }
- public void AIFiring()
- {
- if (FiringAI == true && base.isAI == true)
- {
- if (canFire == true)
- {
- FiringMethod();
- StartCoroutine(CDCheck());
- }
- }
- }
- void FiringMethod()
- {
- if (base.isGuided == false)
- {
- StartCoroutine(TorpedoSalvo());
- }
- else if ((base.isGuided == true) && (torpedo_Target != null))
- {
- base.AssignTarget(torpedo_Target);
- StartCoroutine(TorpedoSalvo());
- }
- }
- IEnumerator TorpedoSalvo()
- {
- torpedoCount = 0;
- while (torpedoCount < torpedoAmt)
- {
- base.LaunchTorpedos();
- torpedoCount++;
- yield return new WaitForSeconds(t_Delay);
- }
- }
- IEnumerator CDCheck() //checks if the player can fire a salvo of torpedos
- {
- canFire = false;
- yield return new WaitForSeconds(cooldown);
- canFire = true;
- }
- void AssignTarget()
- {
- raycastPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
- hitObj = Physics2D.Raycast(raycastPos, Vector2.zero);
- if (hitObj.collider != null)
- {
- if (hitObj.collider.gameObject.tag == "Enemy_C")
- {
- torpedo_Target = hitObj.collider.gameObject;
- }
- }
- else if (hitObj.collider == null)
- {
- torpedo_Target = null;
- Debug.Log("Please select a target");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement