Hi, guys, I have a problem, but it kinda hard to explain, so I will go with the title and images instead, here we go:
You see, I’m trying to make a script named ‘HellBulletManager.cs’
They are almost complete, but have some bugs/unexpected results in some parts…
So, here my observation of the flow while debugging, and I found out the problem, but I don’t know how will I fix this:
(For example: The bug starts when I set the linearAmount atleast 3 or more and together with delayLinear more than 0…) Zoom the image to see where are the problem…
The complete script is here; the code is long, but I just want you to focus on the image above: (and I recommend (if you want) to download the project I attached in zip file below)
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[System.Serializable]
public class BulletModification {
[Header("Modify Cluster:")]
public float startSpeed = 1f;
public enum generateAcceleration {
byUnit,
byPercentage
} public generateAcceleration accelerationType;
public float acceleration;
public float speedRange = 1f;
public int damage = 20;
public float lifeSpan = 5f;
}
[System.Serializable]
public class TransformFormula {
//[Header("Stir Bullet:")]
[Header("Mirror Bullet:")]
[Tooltip("0 means all copies will be on sync, beyond that will make delay offset speed; 100 makes the last delay copy to stationary, 200 makes go to opposite direction. Set delayAmount above 0 to see result")]
[Range(0,200)] public float speedOffset;
[Tooltip("Number of clone bullets for offset speed. Set speedOffset to work with")]
[Range(0,3)] public int delayAmount;
[Tooltip("Number of clone bullets shoot parallel to each other")]
[Range(1,128)] public int linearAmount = 1;
public enum spaceType {
byUnitAway,
byOverallWidth
}; [Tooltip("How parallel bullets take up space")] public spaceType areaOccupy;
[Tooltip("The amount of parallel bullets away each other or their general width as one group")]
public float spacingValue;
[Tooltip("Number in seconds; parallel from the middle will start immediately, then delay start to the next neighbor line")]
[Range(0,20)] public float delayLinear;
[Header("Spray Bullet:")]
[Tooltip("Spread the rays exact to spreadAngle")]
public bool angleFilled;
[Tooltip("The degree angle of an arc be made for rayAmount")]
[Range(0,360)] public float spreadAngle;
[Tooltip("The number of copy bullet as rays restricted by spreadAngle")]
[Range(1,32)] public int rayAmount = 1;
[Tooltip("The radius offset of the center of the ray")]
public float spawnOffsetRadius;
[Tooltip("Number in seconds; the first ray will start immediately, then delay start to the next neighbor ray")]
[Range(0,20)] public float delayRay;
}
[System.Serializable]
public class TransformPattern {
[Header("Bullet Patterns:")]
public Vector2 respawnOffset;
[Tooltip("Sliding the respawn origin of bullet sideward from left to right length-based over given duration")]
public float linearMagnitude;
public enum linearMotionType{
Linear,
Wave
}; public linearMotionType linearFlow;
public enum linearDirection{
left_Right,
right_Left,
center_Right,
center_Left
}; public linearDirection linearPoint;
[Tooltip("Move with one direction or play ping pong")]
public bool pingPong = true;
[Tooltip("The spin progress over given duration; Note: clinch with 'Linear Magnitude'")]
public float spinMotion;
public enum spinMotionType {
Linear,
Wave
}; public spinMotionType spinFlow;
public enum spinDirection{
left_Right,
right_Left,
center_Right,
center_Left
}; public spinDirection spinPoint;
[Tooltip("Merry-go-around or not")]
public bool swingBack = false;
[Tooltip("As it says; offset vertically and/or horizontally -_-")]
public Vector2 masterOffset;
[Tooltip("Offset overall rotation with parent object, but only in z-axis, any problem with that?! Note: doesn't spin over time, use spinMotion or bullet formula instead, or use emitter and make it spin via other script (or animation?)")]
public float masterRotation;
[Tooltip("Offset rotation disregarding linear orientation")]
public float offsetRotation;
}
[System.Serializable]
public class TimeLine {
[Header("Bullet Time:")]
[Tooltip("Ready to execute one time once timeCode reaches")]
public bool active = true;
[Tooltip("Time in seconds to start the bullet party")]
public float start = 0f;
[Tooltip("Time in seconds to finish one pattern")]
public float duration = 1f;
[Tooltip("Multiply the duration to continue executing the pattern")]
public int execute = 1;
[Tooltip("Number of bullet emits in one span of duration harmonizing with pattern; Note: minimum fire rate will not less than 0.01 sec, or else actionPulse will be deducted")]
public int actionPulse = 1;
[Header("Bullet Element:")]
[Tooltip("To certainly choose none, input less than 0")]
public int pattern;
[Tooltip("To certainly choose none, input less than 0")]
public int formula;
[Tooltip("To certainly choose none, input less than 0")]
public int modification;
}
[System.Serializable]
public class BulletSpawn {
[Tooltip("Your title, definition, description, speech, message, or whatever; :Optional:")]
public string name;
public GameObject bulletPrefab;
[Tooltip("Spawn point: object attached with this script act as default emitter, if leave empty")]
public List<GameObject> emitter;
public List<TimeLine> bulletTime;
}
[System.Serializable]
public class BulletFlow {
/* Note: for the future viewer; why no 'public bool active'?
* No need, I found it useless; use/code timeHalt + reset = inactive (if you want to extend this code)... */
public bool reset;
public bool timeHalt;
public bool looping;
[Tooltip("Set loopQuantity to zero for infinite loop")]
public int loopQuantity;
[Tooltip("What for? Delay the start time of timeCode")]
public float delayStart;
[Tooltip("Behold the time holder! NOLI ME TANGERE, if you don't know me what I am for")]
public float timeCode;
}
public class ProcessResults {
public bool patternExist = false;
public Vector3 totalPosition = Vector3.zero;
public Quaternion totalRotation = Quaternion.identity;
public bool formulaExist = false;
public bool modificationExist = false;
public int j, k, l = 0;
public bool primaryRay = false;
public float raySpacing = 0;
public bool primaryLinear = false;
public float linearSpacing = 0;
public bool primaryBullet = false;
public float baseSpeed, baseAcceleration, baseMaxSpeed = 0f;
}
public class HellBulletManager : MonoBehaviour {
[Header("Bullet Manager:")]
public BulletFlow bulletRush;
public float _totalDuration;
private float _loopQuantity;
public List<BulletSpawn> hellBullets;
[Header("Bullet Transform:")]
public List<TransformPattern> bulletPattern = new List<TransformPattern> ();
[Header("Bullet Properties:")]
public List<TransformFormula> bulletFormula;
public List<BulletModification> bulletModification;
// Use this for initialization
void Start () {
_totalDuration = 0f;
_loopQuantity = bulletRush.loopQuantity;
if (bulletFormula.Count > 0)
foreach (TransformFormula thisFormula in bulletFormula)
{
//using [Range(min,max)] and min set to 1, but the default stay to 0; this is use to fix the min when game starts
if (thisFormula.linearAmount == 0)
thisFormula.linearAmount = 1;
if (thisFormula.rayAmount == 0)
thisFormula.rayAmount = 1;
}
}
void FixedUpdate () {
if (bulletRush.reset)
{
bulletRush.reset = !bulletRush.reset;
bulletRush.timeCode = 0f;
foreach (BulletSpawn thisBullet in hellBullets)
{
foreach (TimeLine thisTime in thisBullet.bulletTime)
{
thisTime.active = true;
}
}
}
if (bulletRush.timeHalt)
{
return;
}
if (bulletRush.delayStart > 0f)
{
bulletRush.delayStart -= Time.deltaTime;
if (bulletRush.delayStart < 0f)
bulletRush.delayStart = 0f;
}
else
{
bulletRush.timeCode += Time.deltaTime;
}
//Make sure taken out all List with null bulletSpawn.bulletPrefab --- Lambda syntax 'COOL AND POWERFUL' they say!
hellBullets.RemoveAll (BulletSpawn => BulletSpawn.bulletPrefab == null);
if (hellBullets.Count > 0)
{
foreach (BulletSpawn thisBullet in hellBullets)
{
if (thisBullet.bulletTime.Count > 0)
{
foreach (TimeLine thisTime in thisBullet.bulletTime)
{
if (thisTime.duration > 0f && _totalDuration < thisTime.start + (thisTime.duration * thisTime.execute))
{
_totalDuration = thisTime.start + (thisTime.duration * thisTime.execute);
}
if (thisTime.active && bulletRush.timeCode >= thisTime.start && thisTime.duration > 0f)
{
thisTime.active = false;
float pulseGap = thisTime.duration / thisTime.actionPulse;
if (pulseGap < 0.01f) {
thisTime.actionPulse = Mathf.FloorToInt(thisTime.duration / 0.01f);
if (thisTime.actionPulse == 0)
return;
pulseGap = thisTime.duration / thisTime.actionPulse;
}
StartCoroutine (startRespawn (thisBullet.bulletPrefab, thisBullet.emitter, thisTime.duration, pulseGap, thisTime.execute, thisTime.pattern, thisTime.formula, thisTime.modification));
}
}
}
}
}
if (bulletRush.timeCode >= _totalDuration)
{
if (bulletRush.looping)
{
if (bulletRush.loopQuantity > 0)
bulletRush.loopQuantity -= 1;
if (bulletRush.loopQuantity > 0 || _loopQuantity == 0)
{
bulletRush.reset = true;
}
else
{
bulletRush.timeHalt = true;
bulletRush.reset = true;
}
}
else
{
bulletRush.timeHalt = true;
bulletRush.reset = true;
}
}
}
IEnumerator startRespawn (GameObject bullet, List<GameObject> emitters, float duration, float fireRate, int execute, int pattern, int formula, int modification)
{
TransformPattern patternApply = new TransformPattern ();
TransformFormula formulaApply = new TransformFormula ();
BulletModification modApply = new BulletModification ();
ProcessResults result = new ProcessResults ();
float localTime = 0f;
float readyFire = 0f;
result.patternExist = false;
//bool patternExist = false;
patternApply.respawnOffset = Vector2.zero;
Vector2 respawnOffset = Vector2.zero;
patternApply.linearMagnitude = 0f;
patternApply.linearFlow = TransformPattern.linearMotionType.Linear;
patternApply.linearPoint = TransformPattern.linearDirection.left_Right;
patternApply.pingPong = false;
patternApply.spinMotion = 0f;
patternApply.spinFlow = TransformPattern.spinMotionType.Linear;
patternApply.spinPoint = TransformPattern.spinDirection.left_Right;
patternApply.swingBack = false;
patternApply.masterOffset = Vector2.zero;
patternApply.masterRotation = 0f;
patternApply.offsetRotation = 0f;
result.formulaExist = false;
//bool formulaExist = false;
formulaApply.speedOffset = 0f;
formulaApply.delayAmount = 0;
formulaApply.linearAmount = 1;
formulaApply.areaOccupy = TransformFormula.spaceType.byUnitAway;
formulaApply.spacingValue = 0f;
formulaApply.delayLinear = 0f;
formulaApply.spreadAngle = 0f;
formulaApply.rayAmount = 1;
formulaApply.spawnOffsetRadius = 0f;
formulaApply.delayRay = 0f;
result.modificationExist = false;
//bool modificationExist = false;
modApply.startSpeed = 0f;
modApply.accelerationType = BulletModification.generateAcceleration.byUnit;
modApply.acceleration = 0f;
modApply.speedRange = 0f;
//The game will run but gives me a message error, I don't know where cause of this specifically, may here or above there? Error: ArgumentOutOfRangeException: Argument is out of range. Parameter name: index
if (pattern >= 0 && pattern < bulletPattern.Count) { //Checking... if (bulletPattern[pattern] == null) never assigned 'patternApply = bulletPattern [pattern];'...
result.patternExist = true;
patternApply = bulletPattern [pattern];
/*
patternApply.respawnOffset = bulletPattern[pattern].respawnOffset;
patternApply.linearMagnitude = bulletPattern[pattern].linearMagnitude;
patternApply.linearFlow = bulletPattern[pattern].linearFlow;
patternApply.linearPoint = bulletPattern[pattern].linearPoint;
patternApply.pingPong = bulletPattern[pattern].pingPong;
patternApply.spinMotion = bulletPattern[pattern].spinMotion;
patternApply.spinFlow = bulletPattern[pattern].spinFlow;
patternApply.spinPoint = bulletPattern[pattern].spinPoint;
patternApply.swingBack = bulletPattern[pattern].swingBack;
patternApply.masterOffset = bulletPattern[pattern].masterOffset;
patternApply.masterRotation = bulletPattern[pattern].masterRotation;
patternApply.offsetRotation = bulletPattern[pattern].offsetRotation;
*/
}
if (formula >= 0 && formula <= bulletFormula.Count - 1) { //if (bulletFormula.Exists(BulletSpawn => bulletFormula[formula])) /* <- Sample only: trying '.Exists' for alternatives, but give me some errors; I don't know really how to use it... or how about some '.Contain'? I don't know about it, please help me... THANKS */
result.formulaExist = true;
formulaApply = bulletFormula [formula];
}
if (modification >= 0 && modification <= bulletModification.Count - 1) { //if (bulletModification.Exists(bulletModification[modification]))
result.modificationExist = true;
modApply = bulletModification [modification];
}
//Transform bulletDirector;
float motionPoint;
Vector3 transformPosition = transform.position;
float transformRotation = 0f;
while (localTime < duration * execute && duration > 0f)
{
if (!bulletRush.timeHalt)
{
emitters.RemoveAll (GameObject => GameObject == null);
if (result.patternExist)
{
float respawnOffsetX = Random.Range (-bulletPattern[pattern].respawnOffset.x, bulletPattern[pattern].respawnOffset.x);
float respawnOffsetY = Random.Range (-bulletPattern[pattern].respawnOffset.y, bulletPattern[pattern].respawnOffset.y);
//patternApply.respawnOffset = new Vector2 (respawnOffsetX, respawnOffsetY);
respawnOffset = new Vector2 (respawnOffsetX, respawnOffsetY);
}
bool once = true;
for (int i = 0; i < emitters.Count || once; i++, once = false)
{
int inverse;
inverse = 0;
if (!patternApply.pingPong)
{
if ((patternApply.linearPoint == TransformPattern.linearDirection.left_Right ||
patternApply.linearPoint == TransformPattern.linearDirection.right_Left)
&& Mathf.FloorToInt (localTime * (1f / duration)) % 2 == 1f)
{
inverse = 1;
}
else if ((patternApply.linearPoint == TransformPattern.linearDirection.center_Right ||
patternApply.linearPoint == TransformPattern.linearDirection.center_Left)
&& Mathf.FloorToInt ((localTime * (1f / duration)) + 0.5f) % 2 == 1f)
{
inverse = 1;
}
}
motionPoint = 0f;
Vector3 linearOrientation;
if (emitters.Count == 0)
{
linearOrientation = new Vector3 (Mathf.Cos (Mathf.Deg2Rad * (transform.eulerAngles.z + patternApply.masterRotation)), Mathf.Sin (Mathf.Deg2Rad * (transform.eulerAngles.z + patternApply.masterRotation)), 0f);
}
else
{
linearOrientation = new Vector3 (Mathf.Cos(Mathf.Deg2Rad * (emitters[i].transform.eulerAngles.z + patternApply.masterRotation)), Mathf.Sin(Mathf.Deg2Rad * (emitters[i].transform.eulerAngles.z + patternApply.masterRotation)), 0f);
}
if (patternApply.linearFlow == TransformPattern.linearMotionType.Linear)
{
if (patternApply.linearPoint == TransformPattern.linearDirection.left_Right)
{
motionPoint = Mathf.PingPong ((localTime * patternApply.linearMagnitude * (1f / duration)) + (inverse * patternApply.linearMagnitude), patternApply.linearMagnitude) - (patternApply.linearMagnitude * 0.5f);
}
if (patternApply.linearPoint == TransformPattern.linearDirection.right_Left)
{
motionPoint = Mathf.PingPong ((localTime * patternApply.linearMagnitude * (1f / duration)) + (patternApply.linearMagnitude) + (inverse * patternApply.linearMagnitude), patternApply.linearMagnitude) - (patternApply.linearMagnitude * 0.5f);
}
if (patternApply.linearPoint == TransformPattern.linearDirection.center_Right)
{
motionPoint = Mathf.PingPong ((localTime * patternApply.linearMagnitude * (1f / duration)) + (patternApply.linearMagnitude * 0.5f) + (inverse * patternApply.linearMagnitude), patternApply.linearMagnitude) - (patternApply.linearMagnitude * 0.5f);
}
if (patternApply.linearPoint == TransformPattern.linearDirection.center_Left)
{
motionPoint = Mathf.PingPong ((localTime * patternApply.linearMagnitude * (1f / duration)) - (patternApply.linearMagnitude * 0.5f) + (inverse * patternApply.linearMagnitude), patternApply.linearMagnitude) - (patternApply.linearMagnitude * 0.5f);
}
if (!(System.Single.IsNaN (motionPoint) || System.Single.IsInfinity (motionPoint)))
transformPosition = motionPoint * linearOrientation;
else
transformPosition = Vector3.zero;
}
else if (patternApply.linearFlow == TransformPattern.linearMotionType.Wave)
{
if (patternApply.linearPoint == TransformPattern.linearDirection.left_Right)
{
motionPoint = Mathf.Sin (((localTime - (0.5f * duration) + (inverse * duration)) * (1f / duration)) * Mathf.PI) * (patternApply.linearMagnitude * 0.5f);
}
if (patternApply.linearPoint == TransformPattern.linearDirection.right_Left)
{
motionPoint = Mathf.Sin (((localTime + (0.5f * duration) + (inverse * duration)) * (1f / duration)) * Mathf.PI) * (patternApply.linearMagnitude * 0.5f);
}
if (patternApply.linearPoint == TransformPattern.linearDirection.center_Right)
{
motionPoint = Mathf.Sin (((localTime + (inverse * duration)) * (1f / duration)) * Mathf.PI) * (patternApply.linearMagnitude * 0.5f);
}
if (patternApply.linearPoint == TransformPattern.linearDirection.center_Left)
{
motionPoint = Mathf.Sin (((localTime + (duration) + (inverse * duration)) * (1f / duration)) * Mathf.PI) * (patternApply.linearMagnitude * 0.5f);
}
transformPosition = motionPoint * linearOrientation;
}
result.totalPosition = transformPosition + new Vector3 (patternApply.masterOffset.x, patternApply.masterOffset.y) + new Vector3 (respawnOffset.x, respawnOffset.y);// + new Vector3 (patternApply.respawnOffset.x, patternApply.respawnOffset.y);;
if (emitters.Count == 0)
{
result.totalPosition += transform.position;
}
else
{
result.totalPosition += emitters [i].transform.position;
}
int multiplier;
multiplier = 0;
inverse = 0;
if (!patternApply.swingBack)
{
if ((patternApply.spinPoint == TransformPattern.spinDirection.left_Right ||
patternApply.spinPoint == TransformPattern.spinDirection.right_Left)
&& Mathf.FloorToInt (localTime * (1f / duration)) % 2 == 1f)
{
inverse = 1;
}
else if ((patternApply.spinPoint == TransformPattern.spinDirection.center_Right ||
patternApply.spinPoint == TransformPattern.spinDirection.center_Left)
&& Mathf.FloorToInt ((localTime * (1f / duration)) + 0.5f) % 2 == 1f)
{
inverse = 1;
}
multiplier = Mathf.FloorToInt (localTime * (1f / duration));
}
motionPoint = 0f;
if (patternApply.spinFlow == TransformPattern.spinMotionType.Linear)
{
if (patternApply.spinPoint == TransformPattern.spinDirection.left_Right)
{
motionPoint = (Mathf.PingPong ((localTime * patternApply.spinMotion * (1f / duration)) + (patternApply.spinMotion) + (inverse * patternApply.spinMotion), patternApply.spinMotion) - (patternApply.spinMotion * 0.5f)) - (multiplier * patternApply.spinMotion);
}
if (patternApply.spinPoint == TransformPattern.spinDirection.right_Left)
{
motionPoint = (Mathf.PingPong ((localTime * patternApply.spinMotion * (1f / duration)) + (inverse * patternApply.spinMotion), patternApply.spinMotion) - (patternApply.spinMotion * 0.5f)) + (multiplier * patternApply.spinMotion);
}
if (patternApply.spinPoint == TransformPattern.spinDirection.center_Right)
{
motionPoint = (Mathf.PingPong ((localTime * patternApply.spinMotion * (1f / duration)) - (patternApply.spinMotion * 0.5f) + (inverse * patternApply.spinMotion), patternApply.spinMotion) - (patternApply.spinMotion * 0.5f)) - (multiplier * patternApply.spinMotion);
}
if (patternApply.spinPoint == TransformPattern.spinDirection.center_Left)
{
motionPoint = (Mathf.PingPong ((localTime * patternApply.spinMotion * (1f / duration)) + (patternApply.spinMotion * 0.5f) + (inverse * patternApply.spinMotion), patternApply.spinMotion) - (patternApply.spinMotion * 0.5f)) + (multiplier * patternApply.spinMotion);
}
if (!(System.Single.IsNaN (motionPoint) || System.Single.IsInfinity (motionPoint)))
transformRotation = motionPoint;
else
transformRotation = 0f;
}
else if (patternApply.spinFlow == TransformPattern.spinMotionType.Wave)
{
if (patternApply.spinPoint == TransformPattern.spinDirection.left_Right)
{
motionPoint = (Mathf.Sin (((localTime + (0.5f * duration) + (inverse * duration)) * (1f / duration)) * Mathf.PI) * (patternApply.spinMotion * 0.5f)) - (multiplier * patternApply.spinMotion);
}
if (patternApply.spinPoint == TransformPattern.spinDirection.right_Left)
{
motionPoint = (Mathf.Sin (((localTime - (0.5f * duration) + (inverse * duration)) * (1f / duration)) * Mathf.PI) * (patternApply.spinMotion * 0.5f)) + (multiplier * patternApply.spinMotion);
}
if (patternApply.spinPoint == TransformPattern.spinDirection.center_Right)
{
motionPoint = (Mathf.Sin (((localTime + (duration) + (inverse * duration)) * (1f / duration)) * Mathf.PI) * (patternApply.spinMotion * 0.5f)) - (multiplier * patternApply.spinMotion);
}
if (patternApply.spinPoint == TransformPattern.spinDirection.center_Left)
{
motionPoint = (Mathf.Sin (((localTime + (inverse * duration)) * (1f / duration)) * Mathf.PI) * (patternApply.spinMotion * 0.5f)) + (multiplier * patternApply.spinMotion);
}
transformRotation = motionPoint;
}
result.totalRotation = Quaternion.Euler (0f, 0f, transformRotation + patternApply.masterRotation + patternApply.offsetRotation);
if (emitters.Count == 0)
{
result.totalRotation *= transform.rotation;
}
else
{
result.totalRotation *= emitters[i].transform.rotation;
}
if (readyFire <= localTime)
{
//Formulate the bullet if formula exist
if (result.formulaExist)
{
result.primaryLinear = true;
result.primaryRay = true;
result.baseSpeed = 0f;
result.baseAcceleration = 0f;
result.baseMaxSpeed = 0f;
result.linearSpacing = 0f;
if (formulaApply.linearAmount > 1f)
{
if (formulaApply.areaOccupy == TransformFormula.spaceType.byUnitAway)
{
result.linearSpacing = formulaApply.spacingValue;
}
else if (formulaApply.areaOccupy == TransformFormula.spaceType.byOverallWidth)
{
result.linearSpacing = formulaApply.spacingValue / (formulaApply.linearAmount - 1);
}
}
if (formulaApply.rayAmount > 1f && formulaApply.spreadAngle > 0f)
{
if (formulaApply.angleFilled)
result.raySpacing = formulaApply.spreadAngle / (formulaApply.rayAmount - 1);
else
result.raySpacing = formulaApply.spreadAngle / formulaApply.rayAmount;
}
StartCoroutine (DelayRayFormula (bullet, formulaApply, modApply, result));
}
else
{
GameObject currentClone;
//Instantiate the bullet
currentClone = Instantiate (bullet, result.totalPosition, result.totalRotation) as GameObject;
//Initialize the bullet if modification exist
ModSetup (currentClone, modApply, result.modificationExist);
Debug.Log ("INSIDE-else");
}
}
}
if (readyFire <= localTime)
readyFire = localTime + fireRate;
localTime += Time.deltaTime;
}
yield return null;
}
yield return null;
}
void ModSetup (GameObject currentClone, BulletModification modApply, bool modificationExist)
{
ProjectileController projectileController = currentClone.GetComponent<ProjectileController> ();
//Initialize the bullet if modification exist
if (modificationExist) {
Debug.Log ("modApply.startSpeed: " + modApply.startSpeed + " [" + gameObject.name + "->HellBulletManager/ModSetup()]");
projectileController.Modify (modApply.startSpeed, modApply.acceleration, modApply.speedRange, modApply.damage, modApply.lifeSpan);
}
}
IEnumerator DelayRayFormula (GameObject bullet, TransformFormula formulaApply, BulletModification modApply, ProcessResults result)
{
for (result.j = 0; result.j < formulaApply.rayAmount; result.j += 2)
{
if (!result.primaryRay && formulaApply.delayRay > 0f)
yield return new WaitForSeconds (formulaApply.delayRay);
StartCoroutine(DelayLinearFormula (bullet, formulaApply, modApply, result));
if (result.primaryRay)
{
result.primaryRay = false;
}
result.primaryLinear = true;
}
}
IEnumerator DelayLinearFormula (GameObject bullet, TransformFormula formulaApply, BulletModification modApply, ProcessResults result)
{
for (result.k = 0; result.k < formulaApply.linearAmount; result.k += 2)
{
if (!result.primaryLinear && formulaApply.delayLinear > 0f)
yield return new WaitForSeconds (formulaApply.delayLinear);
StartCoroutine (DelayBulletFormula (bullet, formulaApply, modApply, result));
if (result.primaryLinear)
{
result.primaryLinear = false;
}
}
}
IEnumerator DelayBulletFormula (GameObject bullet, TransformFormula formulaApply, BulletModification modApply, ProcessResults result)
{
GameObject currentClone;
List<GameObject> cloneList = new List<GameObject> ();
bool primaryBullet = true;
float speed;
float acceleration;
float maxSpeed;
for (result.l = 0; result.l < formulaApply.delayAmount + 1; result.l++) {
//Instantiate the bullet
if (formulaApply.rayAmount % 2 == 1)
{
if (formulaApply.linearAmount % 2 == 1)
{
cloneList.Add (currentClone = Instantiate (bullet, result.totalPosition, result.totalRotation) as GameObject);
currentClone.transform.Rotate (0f, 0f, result.raySpacing * (result.j * 0.5f));
currentClone.transform.Translate (Vector3.left * (result.linearSpacing * (result.k * 0.5f)));
if (!result.primaryLinear)
{
cloneList.Add (currentClone = Instantiate (bullet, result.totalPosition, result.totalRotation) as GameObject);
currentClone.transform.Rotate (0f, 0f, result.raySpacing * (result.j * 0.5f));
currentClone.transform.Translate (Vector3.left * (result.linearSpacing * (-result.k * 0.5f)));
}
if (!result.primaryRay)
{
cloneList.Add (currentClone = Instantiate (bullet, result.totalPosition, result.totalRotation) as GameObject);
currentClone.transform.Rotate (0f, 0f, result.raySpacing * (-result.j * 0.5f));
currentClone.transform.Translate (Vector3.left * (result.linearSpacing * (result.k * 0.5f)));
if (!result.primaryLinear)
{
cloneList.Add (currentClone = Instantiate (bullet, result.totalPosition, result.totalRotation) as GameObject);
currentClone.transform.Rotate (0f, 0f, result.raySpacing * (-result.j * 0.5f));
currentClone.transform.Translate (Vector3.left * (result.linearSpacing * (-result.k * 0.5f)));
}
}
}
else //if (formulaApply.linearAmount % 2 == 0)
{
cloneList.Add (currentClone = Instantiate (bullet, result.totalPosition, result.totalRotation) as GameObject);
currentClone.transform.Rotate (0f, 0f, result.raySpacing * (result.j * 0.5f));
currentClone.transform.Translate (Vector3.left * ((result.linearSpacing * (result.k * 0.5f)) + (result.linearSpacing * 0.5f)));
cloneList.Add (currentClone = Instantiate (bullet, result.totalPosition, result.totalRotation) as GameObject);
currentClone.transform.Rotate (0f, 0f, result.raySpacing * (result.j * 0.5f));
currentClone.transform.Translate (Vector3.left * ((result.linearSpacing * (-result.k * 0.5f)) - (result.linearSpacing * 0.5f)));
if (!result.primaryRay)
{
cloneList.Add (currentClone = Instantiate (bullet, result.totalPosition, result.totalRotation) as GameObject);
currentClone.transform.Rotate (0f, 0f, result.raySpacing * (-result.j * 0.5f));
currentClone.transform.Translate (Vector3.left * ((result.linearSpacing * (result.k * 0.5f)) + (result.linearSpacing * 0.5f)));
cloneList.Add (currentClone = Instantiate (bullet, result.totalPosition, result.totalRotation) as GameObject);
currentClone.transform.Rotate (0f, 0f, result.raySpacing * (-result.j * 0.5f));
currentClone.transform.Translate (Vector3.left * ((result.linearSpacing * (-result.k * 0.5f)) - (result.linearSpacing * 0.5f)));
}
}
}
else //if (formulaApply.rayAmount % 2 == 0)
{
if (formulaApply.linearAmount % 2 == 1)
{
cloneList.Add (currentClone = Instantiate (bullet, result.totalPosition, result.totalRotation) as GameObject);
currentClone.transform.Rotate (0f, 0f, (result.raySpacing * (result.j * 0.5f)) + (result.raySpacing * 0.5f));
currentClone.transform.Translate (Vector3.left * (result.linearSpacing * (result.k * 0.5f)));
cloneList.Add (currentClone = Instantiate (bullet, result.totalPosition, result.totalRotation) as GameObject);
currentClone.transform.Rotate (0f, 0f, (result.raySpacing * (-result.j * 0.5f)) - (result.raySpacing * 0.5f));
currentClone.transform.Translate (Vector3.left * (result.linearSpacing * (-result.k * 0.5f)));
if (!result.primaryLinear)
{
cloneList.Add (currentClone = Instantiate (bullet, result.totalPosition, result.totalRotation) as GameObject);
currentClone.transform.Rotate (0f, 0f, (result.raySpacing * (result.j * 0.5f)) + (result.raySpacing * 0.5f));
currentClone.transform.Translate (Vector3.left * (result.linearSpacing * (-result.k * 0.5f)));
cloneList.Add (currentClone = Instantiate (bullet, result.totalPosition, result.totalRotation) as GameObject);
currentClone.transform.Rotate (0f, 0f, (result.raySpacing * (-result.j * 0.5f)) - (result.raySpacing * 0.5f));
currentClone.transform.Translate (Vector3.left * (result.linearSpacing * (result.k * 0.5f)));
}
}
else //if (formulaApply.linearAmount % 2 == 0)
{
cloneList.Add (currentClone = Instantiate (bullet, result.totalPosition, result.totalRotation) as GameObject);
currentClone.transform.Rotate (0f, 0f, result.raySpacing * (result.j * 0.5f));
currentClone.transform.Translate (Vector3.left * ((result.linearSpacing * (result.k * 0.5f)) + (result.linearSpacing * 0.5f)));
cloneList.Add (currentClone = Instantiate (bullet, result.totalPosition, result.totalRotation) as GameObject);
currentClone.transform.Rotate (0f, 0f, result.raySpacing * (result.j * 0.5f));
currentClone.transform.Translate (Vector3.left * ((result.linearSpacing * (-result.k * 0.5f)) - (result.linearSpacing * 0.5f)));
cloneList.Add (currentClone = Instantiate (bullet, result.totalPosition, result.totalRotation) as GameObject);
currentClone.transform.Rotate (0f, 0f, result.raySpacing * (-result.j * 0.5f));
currentClone.transform.Translate (Vector3.left * ((result.linearSpacing * (result.k * 0.5f)) + (result.linearSpacing * 0.5f)));
cloneList.Add (currentClone = Instantiate (bullet, result.totalPosition, result.totalRotation) as GameObject);
currentClone.transform.Rotate (0f, 0f, result.raySpacing * (-result.j * 0.5f));
currentClone.transform.Translate (Vector3.left * ((result.linearSpacing * (-result.k * 0.5f)) - (result.linearSpacing * 0.5f)));
}
}
foreach (GameObject thisClone in cloneList)
ModSetup (thisClone, modApply, result.modificationExist);
if (primaryBullet) {
ProjectileController projectileController = currentClone.GetComponent<ProjectileController> ();
primaryBullet = false;
result.baseSpeed = projectileController.getSpeed ();
result.baseAcceleration = projectileController.getAcceleration ();
result.baseMaxSpeed = projectileController.getMaxSpeed ();
}
if (formulaApply.delayAmount > 0)
{
// 100 setSpeed * 1 - (bulletIndexNum * ((1 - (1 - (100 setValue / 100 valueRange))) / (4 bulletCount - 1))); /* Sample! */
speed = result.baseSpeed * (1 - (result.l * ((1 - (1 - (formulaApply.speedOffset / 100))) / (formulaApply.delayAmount))));
acceleration = result.baseAcceleration * (1 - (result.l * ((1 - (1 - (formulaApply.speedOffset / 100))) / (formulaApply.delayAmount))));
maxSpeed = result.baseMaxSpeed * (1 - (result.l * ((1 - (1 - (formulaApply.speedOffset / 100))) / (formulaApply.delayAmount))));
}
else
{
speed = result.baseSpeed;
acceleration = result.baseAcceleration;
maxSpeed = result.baseMaxSpeed;
}
foreach (GameObject thisClone in cloneList)
{
ProjectileController projectileController = thisClone.GetComponent<ProjectileController> ();
if (result.modificationExist)
projectileController.Modify (speed, acceleration, maxSpeed, modApply.damage, modApply.lifeSpan);
else
projectileController.ModifyMotion (speed, acceleration, maxSpeed);
}
cloneList.Clear ();
}
yield return null;
}
}
I will also attach my simplified project here, to see it first hand:
Hell Bullet Tester.zip
Thank you… your help are greatly appreciated!

3212212–245939–Hell Bullet Tester.zip (1.24 MB)