Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class BattlecruiserAI : BaseAILogic
- {
- public ShipHealth ship_Hp;
- public bool isWandering;
- public bool forwardRayHit;
- public float forwardRayAmt;
- public GameObject[] missileRacks;
- Proj_Tube missileRackScript;
- public int missileID;
- public GameObject[] torpedoRacks;
- Proj_Tube torpedoRackScript;
- SpawnT_Tubes spawn_TT;
- public int torpedoID;
- public float aggroDistance;
- public float engageDistance;
- float currDist;
- // Start is called before the first frame update
- void Start()
- {
- ship_Hp = base.shipAI.GetComponent<ShipHealth>();
- spawn_TT = GetComponentInChildren<SpawnT_Tubes>();
- }
- // Update is called once per frame
- void Update()
- {
- GetEngageDist();
- FrontalRaycast();
- //Debug.Log("Distance to player:" + currDist);
- if (currDist > stoppingDist)
- {
- MoveToDestination(getDistance(Player.transform.position),Player.transform.position);
- }
- if (currDist < engageDistance)
- {
- missileID = 0;
- UseMissiles();
- }
- else if (currDist > engageDistance)
- {
- missileID = 0;
- DontUseMissiles();
- }
- }
- void GetEngageDist()
- {
- currDist = getDistance(Player.transform.position);
- }
- void FrontalRaycast()
- {
- Ray ObjectRay = new Ray(transform.position + (transform.right * 2), transform.right * forwardRayAmt);
- Debug.DrawRay(transform.position + (transform.right * 2), transform.right * forwardRayAmt,Color.green);
- RaycastHit2D hit = Physics2D.Raycast(ObjectRay.origin,ObjectRay.direction);
- if (hit.collider != null)
- {
- if (hit.collider.tag == "Player_C")
- {
- Debug.Log("Target in Range:" + hit.collider.name);
- forwardRayHit = true;
- //Debug.Log("Current Distance:" + currDist);
- while (torpedoID < torpedoRacks.Length)
- {
- torpedoRackScript = torpedoRacks[torpedoID].GetComponentInChildren<Proj_Tube>();
- torpedoRackScript.FiringAI = forwardRayHit;
- Debug.Log("Torpedo Rack:" + torpedoID + " Firing");
- torpedoID++;
- }
- }
- }
- else if (hit.collider == null)
- {
- Debug.Log("No collider detected");
- forwardRayHit = false;
- }
- }
- void UseMissiles()
- {
- while (missileID < missileRacks.Length)
- {
- missileRackScript = missileRacks[missileID].GetComponentInChildren<Proj_Tube>();
- missileRackScript.torpedo_Target = Player;
- missileRackScript.FiringAI = true;
- //Debug.Log("Missile Rack:" + missileID + " Firing.");
- missileID++;
- }
- }
- void DontUseMissiles()
- {
- while (missileID < missileRacks.Length)
- {
- missileRackScript = missileRacks[missileID].GetComponentInChildren<Proj_Tube>();
- missileRackScript.torpedo_Target = null;
- missileRackScript.FiringAI = false;
- missileID++;
- }
- }
Add Comment
Please, Sign In to add comment