// Firing your laser public void fire() { GameObject target = GetComponent <TargetFinder>().getTarget(faction); Rigidbody2D rigidbody = GetComponent <Rigidbody2D>(); rigidbody.velocity = Vector3.zero; if (target == null) { return; } if (Vector3.Distance(transform.position, target.transform.position) > getEffectiveDistance()) { return; } if (ammunition > 0) { Vector3 firePoint = transform.position; ShipDefinitions.DrawLine(firePoint, target.transform.position, color1, 0.1f); ShipDefinitions.DrawLine(firePoint, target.transform.position, color2, 0.12f); ShipDefinitions.DrawLine(firePoint, target.transform.position, color1, 0.14f); ShipDefinitions.DrawLine(firePoint, target.transform.position, color2, 0.1f); target.GetComponent <ShipIntf>().isHit(damage); ammunition--; } target = null; }
// Use the DrawLine method to draw a square public static void DrawSquare(Vector3 bottomLeft, Vector3 topRight, Color color, float duration = 0.2f, float width = 0.075f) { Vector3 bottomRight = new Vector3(topRight.x, bottomLeft.y); Vector3 topLeft = new Vector3(bottomLeft.x, topRight.y); ShipDefinitions.DrawLine(bottomLeft, bottomRight, color, duration, width); ShipDefinitions.DrawLine(bottomLeft, topLeft, color, duration, width); ShipDefinitions.DrawLine(topRight, bottomRight, color, duration, width); ShipDefinitions.DrawLine(topRight, topLeft, color, duration, width); }
// Update is called once per frame void Update() { if (manualShip != null) { Vector3 bottomLeft = manualShip.transform.position - new Vector3(0.01f, 0.01f); Vector3 topRght = manualShip.transform.position + new Vector3(0.01f, 0.01f); ShipDefinitions.DrawSquare(bottomLeft, topRght, Color.yellow, 2 * Time.deltaTime); } if (Input.GetButtonDown("Pause")) { if (pausedOnce) { return; } pausedOnce = true; if (!paused) { GameObject[] objects = UnityEngine.Object.FindObjectsOfType <GameObject>(); foreach (GameObject obj in objects) { if (obj.GetComponent <Particle>() != null) { Particle particle = obj.GetComponent <Particle>(); particle.pause(); } if (obj.GetComponent <ShipController>() != null) { ShipController particle = obj.GetComponent <ShipController>(); particle.pause(); } } } else { GameObject[] objects = UnityEngine.Object.FindObjectsOfType <GameObject>(); foreach (GameObject obj in objects) { if (obj.GetComponent <Particle>() != null) { Particle particle = obj.GetComponent <Particle>(); particle.unpause(); } if (obj.GetComponent <ShipController>() != null) { ShipController ctrl = obj.GetComponent <ShipController>(); ctrl.unpause(); } } } paused = !paused; } if (Input.GetButtonUp("Pause")) { pausedOnce = false; } if (paused) { Color targetLinePlayer = Color.green; Color targetLineEnemy = Color.red; targetLinePlayer.a = 30; GameObject[] objects = UnityEngine.Object.FindObjectsOfType <GameObject>(); foreach (GameObject obj in objects) { if (obj.GetComponent <ShipController>() != null) { ShipController ctrl = obj.GetComponent <ShipController>(); if (ctrl.getTarget() != null) { if (ctrl.getFaction() == ShipDefinitions.Faction.PlayerAffil || ctrl.getFaction() == ShipDefinitions.Faction.Player) { ShipDefinitions.DrawLine(obj.transform.position, ctrl.getTarget().transform.position, targetLinePlayer, 2 * Time.deltaTime, 0.01f); } else if (ctrl.getFaction() == ShipDefinitions.Faction.Enemy) { ShipDefinitions.DrawLine(obj.transform.position, ctrl.getTarget().transform.position, targetLineEnemy, 2 * Time.deltaTime, 0.01f); } } } } } }