Is there some way I can adapt my current script to only fire in a forward facing 250 zone? How about a aft version? So basically I want to check and make sure my selected target is within a 250 degree targeting zone based on the forward section of the ship, if not in arc then abort the firing sequence. I will also need to mod that for a aft one also which shouldn’t be to hard. Here is my current script…
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(LineRenderer))]
public class BeamArray : MonoBehaviour
{
LineRenderer line;
public Material lineMaterial;
bool phaser = false;
public AudioClip sound;
void Start()
{
line = GetComponent<LineRenderer>();
line.SetVertexCount(2);
line.renderer.material = lineMaterial;
line.SetWidth(0.1f, 0.25f);
line.enabled = false;
}
void Update()
{
var script = GameObject.Find("aaMain Camera").GetComponent<SelectTarget>();
if(Input.GetKeyDown("space") && phaser == false && script.gui == "yes")
{
phaser = true;
StartCoroutine (pulsetime());
}
}
IEnumerator pulsetime()
{
var script = GameObject.Find("aaMain Camera").GetComponent<SelectTarget>();
line.enabled = true;
AudioSource.PlayClipAtPoint(sound, Camera.main.transform.position);
RaycastHit hit;
if (Physics.Linecast(transform.position, script.selectedTarget.transform.position, out hit))
{
if(script.Shields == false)
{
print("Shields Down, damage going to hull!");
hit.transform.SendMessage("ApplyDamage", 700, SendMessageOptions.DontRequireReceiver);
}
if(script.Shields == true)
{
// vector from the target center to the hit position
Vector3 hitDirection = hit.point - script.selectedTarget.transform.position;
Transform targetTransform = script.selectedTarget.transform;
float angleForward = Vector3.Angle(hitDirection, -(targetTransform.up));
float angleBack = Vector3.Angle(hitDirection, targetTransform.up);
float angleRight = Vector3.Angle(hitDirection, targetTransform.right);
float angleLeft = Vector3.Angle(hitDirection, -(targetTransform.right));
float angleTop = Vector3.Angle(hitDirection, targetTransform.forward);
float angleBot = Vector3.Angle(hitDirection, -(targetTransform.forward));
string shieldHit = "";
float minAngle = 180;
if (angleForward < minAngle)
{
shieldHit = "ApplyShieldDamageForward";
minAngle = angleForward;
}
if (angleBack < minAngle)
{
shieldHit = "ApplyShieldDamageAft";
minAngle = angleBack;
}
if (angleRight < minAngle)
{
shieldHit = "ApplyShieldDamageStarboard";
minAngle = angleRight;
}
if (angleLeft < minAngle)
{
shieldHit = "ApplyShieldDamagePort";
minAngle = angleLeft;
}
if (angleTop < minAngle)
{
shieldHit = "ApplyShieldDamageDorsal";
minAngle = angleTop;
}
if (angleBot < minAngle)
{
shieldHit = "ApplyShieldDamageVentral";
minAngle = angleBot;
}
hit.transform.SendMessage(shieldHit, 700, SendMessageOptions.DontRequireReceiver);
}
}
//wait the cooldown time in a loop
float delay = 1.680f;
while (delay > 0)
{
//update beam endpoints
if(script.Shields == false)
{
line.SetPosition(0, transform.position);
line.SetPosition(1, script.selectedTarget.transform.position);
}
if(script.Shields == true)
{
line.SetPosition(0, transform.position);
line.SetPosition(1, hit.point);
script.selectedTarget.FindChild("Shield Bubble").GetComponent<MeshRenderer>().enabled = true;
}
//decrement delay time
delay -= Time.deltaTime;
//let unity free until next frame
yield return null;
}
line.enabled = false;
phaser = false;
script.selectedTarget.FindChild("Shield Bubble").GetComponent<MeshRenderer>().enabled = false;
}
}
I am feeling so silly with all my complex questions… lol all just learning…
No one wants to read through 160 lines of code, most of which appear to have nothing to do with the question at hand. Maybe if you pruned your code to the relevant bits, you'd get more people responding.
– Dracorat