This is my ballistics class, there’s a bit of commented out code because i have problems with target at different elevations and i’m trying to iron it out.
should be fine for your needs, if i broke it with fiddling tell me and i’ll post the previous version.
hope it helps 
edit: uhh, necro much? next time open a new thread and please explain your problem with you code snippet.
using UnityEngine;
public static class Ballistics {
// Note, doesn't take drag into account.
/// <summary>
/// Calculates the trajectory.
/// </summary>
/// <returns>The trajectory.</returns>
/// <param name="start">Start.</param>
/// <param name="end">End.</param>
/// <param name="muzzleVelocity">Muzzle velocity.</param>
public static BallisticPath CalculateTrajectory(Vector3 start, Vector3 end, float muzzleVelocity){
float vSqr = muzzleVelocity * muzzleVelocity;
//float xx = end.x - start.x;
//float xz = end.z - start.z;
//float x = Mathf.Sqrt(xx * xx + xz * xz);
float x = new Vector3(end.x - start.x, 0, end.z - start.z).magnitude;
float y = start.y - end.y;
float g = Physics.gravity.magnitude;
float uRoot = (vSqr * vSqr) - (g * (g * (x * x) + (2 * y * vSqr)));
if (uRoot < 0.0f)
return null;
float root = Mathf.Sqrt (uRoot);
float bottom = g * x;
//Debug.Log (string.Format ("Height:{0}, Gravity:{1}, Distance:{2}", y, g, x));
return new BallisticPath (
(Mathf.Atan2 (bottom, vSqr + root) * Mathf.Rad2Deg),
(Mathf.Atan2 (bottom, vSqr - root) * Mathf.Rad2Deg)
);
}
/// <summary>
/// Gets the ballistic path.
/// </summary>
/// <returns>The ballistic path.</returns>
/// <param name="startPos">Start position.</param>
/// <param name="forward">Forward direction.</param>
/// <param name="velocity">Velocity.</param>
/// <param name="maxTime">Total time to simulate.</param>
/// <param name="timeResolution">Time from frame to frame.</param>
public static Vector3[] GetBallisticPath(Vector3 startPos, Vector3 forward, float velocity, float maxTime, float timeResolution){
Vector3[] positions = new Vector3[Mathf.CeilToInt(maxTime / timeResolution)];
Vector3 velVector = forward * velocity;
int index = 0;
Vector3 curPosition = startPos;
for (float t = 0.0f; t < maxTime; t += timeResolution) {
if (index >= positions.Length)
break;//rounding error using certain values for maxTime and timeResolution
positions [index] = curPosition;
curPosition += velVector * timeResolution;
velVector += Physics.gravity * timeResolution;
index++;
}
return positions;
}
/// <summary>
/// Checks the ballistic path.
/// </summary>
/// <returns><c>false</c>, if ballistic path was blocked by an object on the Layermask, <c>true</c> otherwise.</returns>
/// <param name="arc">Arc.</param>
/// <param name="allyLM">Anything in this layer will block the path.</param>
public static bool CheckBallisticPath(Vector3[] arc, LayerMask allyLM){
RaycastHit hit;
for (int i = 1; i < arc.Length; i++) {
if (Physics.Raycast (arc [i - 1], arc [i] - arc [i - 1], out hit, (arc [i] - arc [i - 1]).magnitude) && GameMaster.IsInLayerMask(hit.transform.gameObject.layer, allyLM)) {
Debug.DrawRay (arc [i - 1], arc [i] - arc [i - 1], Color.red, 10f);
return false;
} else {
Debug.DrawRay (arc [i - 1], arc [i] - arc [i - 1], Color.green, 10f);
}
}
return true;
}
public static float CalculateMaxRange(float muzzleVelocity){
return (muzzleVelocity * muzzleVelocity) / -Physics.gravity.y;
}
}
public class BallisticPath{//FIXME convert to struct;
public float lowAngle;
public float highAngle;
public BallisticPath (float lowAngle, float highAngle){
this.lowAngle = lowAngle;
this.highAngle = highAngle;
}
public override string ToString ()
{
return string.Format ("Low angle:{0}, High angle:{1}",lowAngle, highAngle);
}
}